I:\VISUAL_BASIC_PROGRAMMING\Two_methods_of_Programming_VISA_GPIB_in_VB6
' VISA GPIB driver methods using NI or Agilent GPIB drivers.
' For visual basic 6, VB6 or ExcelVBA or Excel VBA
Private Sub cmdRUN_Click()
' How to get the visacom driver working with the latest IVIfoundation
' drivers.
' ******************************************************************
' In project reference do not forget to add as a project reference
' VISA COM 3.0 Type Library
' ******************************************************************
' Using this method you get very fine grain control
Dim Result As String
Dim VGaddress As String
Dim ioMgr As VisaComLib.ResourceManager
Set ioMgr = New VisaComLib.ResourceManager
Dim VGb As VisaComLib.FormattedIO488
Set VGb = New VisaComLib.FormattedIO488
Rem VGaddress =
Rem VGadress = "visa://192.168.3.25/GPIB0::22::INSTR" ' Or
Rem VGadress = "GPIB0::2::INSTR"
Rem not valid for RS232 serial GPIB connections
VGaddress = Trim(Text_input.Text)
' trim the result from the text box to remove spaces
Label_output.Caption = "Talking to address :: " + VGaddress + vbLf
Set VGb.IO = ioMgr.Open(VGaddress)
VGb.IO.Timeout = 10000
VGb.WriteString ("*IDN?") ' write SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Sending IEC bus command *IDN? "
+ vbLf
Result = VGb.ReadString ' READ SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Information return by
instrument " + vbLf
Label_output.Caption = Label_output.Caption + Result + vbLf
VGb.IO.Close
End Sub
1 of 2
I:\VISUAL_BASIC_PROGRAMMING\Two_methods_of_Programming_VISA_GPIB_in_VB6
Private Sub cmdOther_method_click()
' This is the other method of access the VISA GPIB devices has less control
' but easier to work with in VB
' ******************************************************************
' In project reference do not forget to add as a project reference
' VISA COM 3.0 Type Library
' ******************************************************************
Dim rm As IResourceManager
Dim msg As IMessage
Dim Result As String
Dim VisaAddress As String
Rem VisaAdress = "visa://192.168.3.25/GPIB0::22::INSTR" ' Or
Rem VisaAdress = "GPIB0::2::INSTR"
Rem not valid for RS232 serial GPIB connections
VisaAddress = Trim(Text_input.Text)
' trim the result from the text box to remove spaces
Label_output.Caption = "Talking to address :: " + VisaAddress + vbLf
Set rm = CreateObject("VISA.GlobalRM")' Set visagpib connection
Set msg = rm.Open(VisaAdress, NO_LOCK, 2000, "") ' Timeout=2000mS max 3000mS
msg.Clear
msg.WriteString "*IDN?" & vbLf ' write SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Sending IEC bus command *IDN? "
+ vbLf
Result = msg.ReadString(256) ' READ SCPI command to VISAGPIB Device
Label_output.Caption = Label_output.Caption + "Information return by
instrument " + vbLf
Label_output.Caption = Label_output.Caption + Result + vbLf
End Sub
2 of 2