To use AppConn in a Visual Basic project, select References from the Project menu and select AppConn from the list of available references. If AppConn does not appear, use the Browse button to select the appconn.dll from the Windows\System32 folder.
Once AppConn is included in the project, all of the AppConn objects will appear in the Visual Basic IntelliSense. If AppConnLib is selected when using the IntelliSense, a list of the AppConn objects will appear. Objects may be declared with or without the AppConnLib prefix. The following declarations are the same:
Dim Session As AppConnTable Dim Session As AppConnLib.AppConnTable
To create an AppConn object, use the new operator as follows:
Set Session = new AppConnTable
Visual Basic IntelliSense provides a list of properties and methods available for the object. IntelliSense also provides a list of the parameters for methods. The IntelliSense also supplies the parameter type. Optional parameters are enclosed in square brackets (e.g. [varUserID] ).
IntelliSense will also show the return type for methods that have parameters. variables can be set to object properties and method return values. If the property return type is a COM object, Visual Basic requires using Set; otherwise a simple assignment statement can be used.
Dim Rec As AppConnRecordSet Dim Index As Long Dim Connected As Boolean ' Requires Set because method returns a COM object Set Rec = Session.FetchRecords ' Does not require Set because method returns a long Long Index = Session.GetCurrentRecordIndex 'Does not require Set because property is a Boolean Connected = Session.IsConnected
Visual Basic requires that properties and methods that return a value use parentheses when parameters are included in the call.
' Does not require parentheses because all of the parameters are optional ' and none are included Set Recs = Session. FetchRecords ' Requires parentheses because a parameter is included Set Recs = Session. FetchRecords (1) 'Requires parentheses because parameters are included and a return value is used Set Recs = PerformTableProcedure("Pets", "Get") ' Does not require parentheses because return value is not used PerformTableProcedure "Pets", "Delete"
You can use the Web Builder tool to create projects based on the "demo" models provided with Verastream Host Integrator and then examine the code in your projects to see how the connector works.
Examples for individual methods are included with the Visual Basic Methods Reference.
Resume Next will ignore the error and continue executing the next statement:
On Error Resume Next
GoTo 0 will use the default error handler:
On Error GoTo 0
GoTo <label> will cause the program to jump to the label and execute the next statement.
On Error GoTo HandleError Session.ConnectToModel "localhost", "CCSDemo" Exit Sub ErrorHandler: MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
Visual Basic allows variable type parameters. For example, the Item method of the AppConnStringMap can take either a number (the index of an element) or a string (the key of an element). The method will determine the type of the parameter and return the correct element for that type.
Dim Attributes As AppConnStringMap Dim Attribute as String Set Attributes = new AppConnStringMap 'Create the string map Attributes.Add("LastName", "Culver") 'Populate the string map Attribute = Attributes.Item(1) 'Get the first element (VisualBasic indexes start at 1) Attribute = Attributes.Item("LastName") 'Get the element named "LastName"
Default methods can be defined for COM objects. When the method name is omitted Visual Basic will use the default method. For the AppConnRecordSet, AppConnRecord, AppConnModelRecord, AppConnStringList, and AppConnStringMap the Item method is defined as the default method. The calls to the Item method can be written as follows:
Attribute = Attributes(1) Attribute = Attributes("LastName")
When the parameter is a string, the default method can be invoked using the exclamation point (!) and the parameter string without quotes.
Attribute = Attributes!LastName
The AppConnRecordSet, AppConnRecord, AppConnModelRecord, AppConnStringList, and AppConnStringMap objects are defined as COM collections, which means that VisualBasic can iterate over the collection using the For Each…Next construct. In the following example a For Each statement is imbedded inside a For Each statement to iterate over each record in a record set and each field in the record:
Dim Rec Dim Field Dim Line As String For Each Rec In Recs Line = "Fields:" For Each Field In Rec Line = Line + " " + Field Next Next
© 1999-2007 Attachmate Corporation. All rights reserved. Terms of Use.