The following code listing shows an example of Active Expert Visual Basic code that communicates with the TUXEDO system to perform banking services; the same two services (Inquiry and Withdraw) are used. The name of the instance of the control in this example is Account
.
Listing 4-22 OLE Automation View as an ActiveX Control
Dim InquiryReply As Object
Dim accountid As Long
Dim samount As String
Dim sbal As String
Dim bal As Single
Dim excep As Variant
Sub Button_Clicked()
On Error Goto errorhandler `set up error(exception) handling
accountid = tbAccount.Text ` get the accountid from text box
Call Account.Withdraw(accountid, sbal, excep) ` synchronous invocation
Select Case (excep.EX_majorCode) ` Active Expert style error handling
Case 0: ` no error
tbBalance.Text = sbal
Case 1: 'system exception
MsgBox session.get_error_text(excep.EX_minorCode)
Case 2: 'user exception
MsgBox CStr(excep.tpurcode) & "Application error"
End Select
Set InquiryReply = Account.InquiryAsync (accountid) `asynchronous invocation
errorhandler: ` Visual Basic style error handling
MsgBox Err.Description
End Sub
Sub Account_InquiryDone(ByValue Reply As
Variant, Optional ByValue Exception as
Variant)
`Event callback function
If Reply = InquiryReply Then
`retrieve the reply
Call Reply.get_InquiryReply(sbal, excep)
Select Case (excep.EX_majorCode) ` Active Expert style error handling
Case 0: ` no error
tbBalance.Text = sbal
Case 1: 'system exception
MsgBox session.get_error_text(excep.EX_minorCode)
Case 2: 'user exception
MsgBox CStr(excep.tpurcode) & "Application error"
End Select
End If
End Sub
Listing 4-23 Using OLE Automation View as an OLE Automation Server
Dim Account As Object
Dim InquiryReply As Object
Dim accountid As Long
Dim samount As String
Dim sbal As String
Dim bal As Single
On Error Goto errorhandler `set up error(exception) handling
Account = CreateObject ("Banking.Account")
accountid = tbAccount.Text ` get the accountid from text box
Call Account.Withdraw(accountid, sbal) ` synchronous invocation
tbBalance.Text = sbal
errorhandler: ` Visual Basic exceptions are used
MsgBox Err.Description