Using Visual Basic as a Client


 

When creating a VB client for use with the PL/B Automation Server, begin by selecting the References menu item from the Project menu. Find the PL/B Runtime 1.0 Type Library entry and select it. This adds the type library information to your project.

 

Next, add the following to the General Declarations section of your Visual Basic form:

 

Dim PlbAppObj As PlbApp.PlbApp

Dim WithEvents PlbProgObj As PlbApp.PlbProg

 

Now create a button and set the caption property to ‘Start Component’. The button should have the following code:

 

Private Sub Command1_Click()

  Set PlbProgObj = Nothing

  Set PlbAppObj = New PlbApp.PlbApp

 

  Set PlbProgObj = PlbAppObj.CreateProgram

 

  PlbProgObj.Run ("sampsrv")

  plbProgObj.EventSend 1, "Smith"

 

  Set PlbAppObj = Nothing

End Sub

 

This code first destroys any previous reference to the PlbProgObj variable. It then makes a connection to the PL/B Automation Server’s application object. Next, it creates a new program object using the application object's CreateProgram method. The program then uses the program object to start the "sampsrv" PL/B component program. The next line of code makes a request to look up "Smith". Finally the program releases the application object from the PlbAppObj variable.

 

To continue the example program, add a listbox to the form. Add the following code to the PlbProgObj_UserEvent1 event. This will format the event result and place it into the listbox.

 

Private Sub PlbProgObj_UserEvent1(Optional ByVal arg1 As Variant...)

  Dim temp As String

 

  temp = "Name: " & arg1 & " Phone: " & arg2

  List1.AddItem (temp)

End Sub

 

Now, add the following code to the Sub PlbProgObj_UserEvent2 event. This code tells the component to exit and places some information in the listbox.

 

Private Sub PlbProgObj_UserEvent2(Optional ByVal arg1 As ...)

  PlbProgObj.EventSend (2)

  List1.AddItem ("All records found")

End Sub

 

Finally, add the following code to the Sub PlbProgObj_Exit event. This code indicates that the exit event was seen and releases the PlbProgObj variable.

 

Private Sub PlbProgObj_Exit(ByVal exitStatus As Boolean)

  List1.AddItem ("Program exit seen")

  Set PlbProgObj = Nothing

End Sub

 

 

See Also: Automation



Compiler and Runtime Options Using PL/B as a Client Using VBScript as a Client