You can use different approaches to error handling in the VB program:
•Check the value of the Err.Number variable after execution of the VB operator, which contains the call to the COM server object.
•Use On Error GoTo VB operator.
These approaches are represented in the examples below. The following operator causes an error in VB program as "S13" value of the DEFine property is incorrect.
app.SCPI.PARameter.DEFine = "S13" |
In the first example, the value of the Err.Number variable is checked after execution of the VB operator, which contains the call to the COM server object. The On Error Resume Next directive instructs VB not to interrupt the program execution when the error is detected, but to pass control to the next operator in natural order.
Dim app Public Sub HandleError1() Set app = CreateObject("S2VNA.Application") On Error Resume Next app.SCPI.PARameter.DEFine = "S13" If Err.Number <> 0 Then Msg = "Error # " & Str(Err.Number) & " was generated by " &_ Err.Source & Chr(13) & Err.Description MsgBox Msg,,"Error" End If ... End Sub |
In the second example, the On Error GoTo ErrHandler directive instructs VB to interrupt the program execution when the error is detected and to pass control to ErrHandler label.
Dim app Public Sub HandleError2() Set app = CreateObject("S2VNA.Applcation") On Error GoTo ErrHandler app.SCPI.PARameter.DEFine = "S13" ... Exit Sub ErrHandler: Msg = "Error # " & Str(Err.Number) & " was generated by " &_ Err.Source & Chr(13) & Err.Description MsgBox Msg,,"Error" End Sub |