10
Error Handling
You can use different approaches to error handling in VB program:
check the value of Err.Number variable after execution of VB operator, which
contains the call to 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 COM server object.
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("TRVNA.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