Agilent 4155C/4156C VXIplug&play Driver User’s Guide, Edition 4 3-5
Programming Examples for Visual Basic Users
Programming Basics
’Closing the session ********************************************
ret = hp4156b_close(vi) ’30
check_err vi, ret
msg = "Click OK to stop the program."
MsgBox msg, vbOKOnly, ""
End Sub
’---------------------------------------------------------------- 36
Sub perform_meas(vi As Long, ret As Long)
’insert program code
End Sub
’---------------------------------------------------------------- 41
Sub check_err(vi As Long, ret As Long)
Dim inst_err As Long
Dim err_message As String * 250
Dim msg As String
Dim retStatus As Long
If VI_SUCCESS > ret Then
If (hp4156b_INSTR_ERROR_DETECTED = ret) Then
retStatus = hp4156b_error_query(vi, inst_err, err_message)
msg = "Instrument Error: " & inst_err & Chr(10) & Chr(10) & err_message
MsgBox msg, vbOKOnly, ""
Else
retStatus = hp4156b_error_message(vi, ret, err_message)
msg = "Driver Error: " & ret & Chr(10) & Chr(10) & err_message
MsgBox msg, vbOKOnly, ""
End If
End If
End Sub
Line Description
30 Disables the software connection with the Agilent 4155/4156.
31 Calls the check_err subprogram to check if an error status is returned for the line 30.
32 to 33 Opens a message box to confirm end of program.
35 End of the Main subprogram.
38 to 40 This is just the declaration of the perform_meas subprogram. Complete the subprogram
that controls the 4155/4156, performs measurement, and displays/saves the results.
41 to last Checks if the passed “ret” value indicates normal status, and returns to the line that
called this subprogram. If the value indicates an instrument error status or a device error
status, a message box will be displayed to show the error message.