1. PI-ServerPickList Tutorial

In this tutorial we illustrate the use of the PI-ServerPickList control by adding it to the Visual Basic tutorial example that we created in Chapter 3.

The complete code for both tutorials can be found in the online help file under Tutorial Code:Adding the PI-ServerPickList Control

Recall that in the example in Chapter 3, we created

1. a dropdown list, used to select a server

2. a login button, used to call the Login method.

In the first PI-SDK Control tutorial project, we will replace both of these items with the PI-ServerPickList control.

  1. STEP 1. SET UP THE WORKSPACE TO USE THE PI-SDK CONTROL

Open the project that you created for the PI-SDK tutorial. If you skipped the PI-SDK tutorial you can copy the tutorial code from the online help.

Follow the instructions in the section called "Adding the PI-SDK Control," above.

From the View/Object Browser menu, you can select PI-SDK Control from the dropdown and browse the methods, properties, and events for the control.

  1. STEP 2: DELETE THE OLD ELEMENTS

On the form, delete the combo box and the Login button from the form by selecting each item with the mouse and then pressing the Delete key. We will replace these with the PISrvPickList control. You should also delete or comment out the code in the Combo1_Click() and the Command2_Click() subroutines. Note that since these controls were just deleted, in order to find the subroutines you will need to set the left dropdown in the Visual Basic IDE to "General"; you should then see the subroutines listed in the right dropdown.

Delete or comment out the Form_Load() subroutine in Form1. This is no longer needed because the PI-ServerPickList control will automatically populate itself and set the default selection to the default server. The last line of code sets the global variable srv. This will be handled in the PI-ServerPickList control's Click event, as we shall see later.

  1. STEP 3: ADD THE NEW CONTROL

From the toolbox, select the PI-ServerPickList control and place it on the form where the combo box used to be. The control populates its own combo box.

The only code that needs to be added is setting the global variable srv. This is done in the PISrvPickList1_Click() event handler:

Private Sub PISrvPickList1_Click()

Set srv = PISrvPickList1.SelectedServer

End Sub

 

  1. STEP 4: TEST THE NEW CONTROL

Save the project. Run the application. When you select a server, notice the line that separates the connected servers from the disconnected servers.

 

  1. STEP 5: AUTOMATIC LOGIN

This step illustrates a way to use the PI-ServerPickList to log in. This approach is useful if you want the login to happen anyway.

This approach configures the control to automatically login as soon as the server is selected. It will attempt to login using the default user and no password; if it fails (usually due to password protection) then the login dialog will be displayed to allow the user to supply a username and password. To configure this option, set the PI-ServerPickList's ConnectOnSelect property to True in Form_Load.

Note: the PI-SDK will attempt to login using the default user and no password whenever data is accessed from a server that is not already connected. This occurs whether or not the PI-ServerPickList is present. So why bother to configure the ConnectOnSelect property? The answer is apparent when the default user name is password protected. If you configure the ConnectOnSelect property, then the Login dialog will automatically be displayed; without it, the PI-SDK will raise an error.

At this point, the Form_Load subroutine looks like this:

Private Sub Form_Load()

PISrvPickList1.ConnectOnSelect = True

End Sub

 

  1. STEP 6: TEST AUTOMATIC LOGIN

Save the project. Run the application. Notice that the default server is connected. (If it was password protected, then you have already been greeted with the login dialog.).

Now select a different server. Note the automatic login to the new server. If you scroll through the list, you will see that each server that is selected gets moved above the line after it is connected.

This completes the PI-ServerPickList tutorial.

Enabling Operational Intelligence