这是窗体的
Option Explicit
''' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
''' Copyright ?2002 Agilent Technologies Inc. All rights reserved.
'''
''' You have a royalty-free right to use, modify, reproduce and distribute
''' the Sample Application Files (and/or any modified version) in any way
''' you find useful, provided that you agree that Agilent Technologies has no
''' warranty, obligations or liability for any Sample Application Files.
'''
''' Agilent Technologies provides programming examples for illustration only,
''' This sample program assumes that you are familiar with the programming
''' language being demonstrated and the tools used to create and debug
''' procedures. Agilent Technologies support engineers can help explain the
''' functionality of Agilent Technologies software components and associated
''' commands, but they will not modify these samples to provide added
''' functionality or construct procedures to meet your specific needs.
''' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'
' This example program calls the module DAQ_34970A to set a scan and
' then get the readings from the instrument. The module DAQ_34970.bas
' was created by the 34970A Code Wizard VB6.0 add in. The module was modified
' to call a routine that places data onto the form.' This code requires a MUX module in slot 1
'
' It demonstrates how to monitor channels set up on the 34970A by calling the
' channel list, allowing the user to select one of the channels, and then getting
' a reading (Monitor) from that channel.
'
Dim Daq As VisaComLib.FormattedIO488Const IO_ADDRESS = "ASRL1::INSTR"
Dim m_ioAddress As String
Dim x As Integer, y As Integer, z As Integer, w As Integer, v As IntegerPublic Sub WriteDataToForm(Readings() As Double, _
Units() As String, _
ChanNumb() As Integer, _
Time() As Date, _
ByVal Sweep As Integer, _
ByVal numberChannels As Integer)
' A call to this routine was added to the code developed by the
' 34970A code Wizard
' This code will fill out the scan text box every time it is executed. ' If you do not use the Units, Channel annotation, or Time when making
' new code, you will have to modify this code.
'
Dim I As Long
Dim lineUnits As String
Dim lineChannels As String
lineUnits = ""
lineChannels = ""
If Sweep = 1 Then
For I = 1 To numberChannels
' We put a heading only for the first sweep
lineUnits = lineUnits & Units(1, I) & vbTab
lineChannels = lineChannels & Str$(ChanNumb(1, I)) & vbTab
Next I
txtScanData.SelText = lineUnits & vbCrLf & lineChannels & vbCrLf
End If For I = 101 To numberChannels
Me.txtScanData.SelText = Format$(Readings(Sweep, I), "0.0e+0") & vbTab
Next I
Me.txtScanData.SelText = vbCrLf
End SubPrivate Sub cmdMonitor_Click()
Dim channel As String If isconnected Then
channel = MonitorChannel
Monitor Daq, txtMonitor, channel
InstrumentError Daq
End IfEnd SubPrivate Sub cmdRefreshChannels_Click()
Me.MousePointer = vbHourglass If isconnected Then
GetScanList Daq, lstChannel
InstrumentError Daq
End If
Me.cmdMonitor.Enabled = True
Me.MousePointer = vbDefaultEnd Sub
Private Sub cmdStartScan_Click()
Me.MousePointer = vbHourglass
If isconnected Then
Me.txtScanData.Text = ""
main_34970A Daq
InstrumentError Daq
cmdRefreshChannels_Click
End If
Me.MousePointer = vbDefault
End SubPrivate Function MonitorChannel() As String
' returns the user selected channel to monitor
Dim Index As Long With lstChannel
Index = .ListIndex
If Index > 0 Then
MonitorChannel = Right$(.List(Index), 3)
Else
MonitorChannel = "Front Panel"
Exit Function
End If
End WithEnd FunctionPublic Sub InstrumentError(Instrument As VisaComLib.FormattedIO488)
Dim reply As String With Instrument
.WriteString "Syst:Error?"
reply = .ReadString
End With If Val(reply) <> 0 Then
MsgBox "Instrument Error: " & vbCrLf & reply, vbCritical
InstrumentError Instrument
End IfEnd Sub
Private Function isconnected() As Boolean
' determines if the instrument is connected, and
' gives a message if not
Dim result() As Variant
Dim oldTimeout As Long On Error GoTo connectError With Daq
oldTimeout = .io.Timeout
.io.Timeout = 1000
.WriteString "*IDN?"
result = .ReadList
.io.Timeout = oldTimeout
End With If InStr(1, result(1), "34970A", vbTextCompare) = 0 Then
GoTo WrongInstrumentError
End If isconnected = True Exit FunctionconnectError:
Daq.io.Timeout = 10000
MsgBox "Instrument not connected. Please check connections and use the Set I/O toolbar button to set the instrument connection."
isconnected = False
Exit Function
WrongInstrumentError:
MsgBox "Incorrect instrument: " & vbCrLf & _
"Expected 34970A " & vbCrLf & _
"Instrument discovered: " & result(1)
isconnected = False
End FunctionPrivate Sub cmdSetIO_Click()
' set the I/O address to the text box in case the
' user changed it.
' bring up the input dialog and save any changes to the
' text box
Dim mgr As VisaComLib.ResourceManager
On Error GoTo ioError m_ioAddress = InputBox("Enter the IO address of the Function Generator", "Set IO address", m_ioAddress) Set mgr = New VisaComLib.ResourceManager
Set Daq = New VisaComLib.FormattedIO488
Set Daq.io = mgr.Open(m_ioAddress)
Exit Sub
ioError:
MsgBox "Set IO error:" & vbCrLf & Err.DescriptionEnd Sub
完全不懂啊,编译出现错误
could not interpret I/O as single number
Option Explicit
''' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
''' Copyright ?2002 Agilent Technologies Inc. All rights reserved.
'''
''' You have a royalty-free right to use, modify, reproduce and distribute
''' the Sample Application Files (and/or any modified version) in any way
''' you find useful, provided that you agree that Agilent Technologies has no
''' warranty, obligations or liability for any Sample Application Files.
'''
''' Agilent Technologies provides programming examples for illustration only,
''' This sample program assumes that you are familiar with the programming
''' language being demonstrated and the tools used to create and debug
''' procedures. Agilent Technologies support engineers can help explain the
''' functionality of Agilent Technologies software components and associated
''' commands, but they will not modify these samples to provide added
''' functionality or construct procedures to meet your specific needs.
''' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'
' This example program calls the module DAQ_34970A to set a scan and
' then get the readings from the instrument. The module DAQ_34970.bas
' was created by the 34970A Code Wizard VB6.0 add in. The module was modified
' to call a routine that places data onto the form.' This code requires a MUX module in slot 1
'
' It demonstrates how to monitor channels set up on the 34970A by calling the
' channel list, allowing the user to select one of the channels, and then getting
' a reading (Monitor) from that channel.
'
Dim Daq As VisaComLib.FormattedIO488Const IO_ADDRESS = "ASRL1::INSTR"
Dim m_ioAddress As String
Dim x As Integer, y As Integer, z As Integer, w As Integer, v As IntegerPublic Sub WriteDataToForm(Readings() As Double, _
Units() As String, _
ChanNumb() As Integer, _
Time() As Date, _
ByVal Sweep As Integer, _
ByVal numberChannels As Integer)
' A call to this routine was added to the code developed by the
' 34970A code Wizard
' This code will fill out the scan text box every time it is executed. ' If you do not use the Units, Channel annotation, or Time when making
' new code, you will have to modify this code.
'
Dim I As Long
Dim lineUnits As String
Dim lineChannels As String
lineUnits = ""
lineChannels = ""
If Sweep = 1 Then
For I = 1 To numberChannels
' We put a heading only for the first sweep
lineUnits = lineUnits & Units(1, I) & vbTab
lineChannels = lineChannels & Str$(ChanNumb(1, I)) & vbTab
Next I
txtScanData.SelText = lineUnits & vbCrLf & lineChannels & vbCrLf
End If For I = 101 To numberChannels
Me.txtScanData.SelText = Format$(Readings(Sweep, I), "0.0e+0") & vbTab
Next I
Me.txtScanData.SelText = vbCrLf
End SubPrivate Sub cmdMonitor_Click()
Dim channel As String If isconnected Then
channel = MonitorChannel
Monitor Daq, txtMonitor, channel
InstrumentError Daq
End IfEnd SubPrivate Sub cmdRefreshChannels_Click()
Me.MousePointer = vbHourglass If isconnected Then
GetScanList Daq, lstChannel
InstrumentError Daq
End If
Me.cmdMonitor.Enabled = True
Me.MousePointer = vbDefaultEnd Sub
Private Sub cmdStartScan_Click()
Me.MousePointer = vbHourglass
If isconnected Then
Me.txtScanData.Text = ""
main_34970A Daq
InstrumentError Daq
cmdRefreshChannels_Click
End If
Me.MousePointer = vbDefault
End SubPrivate Function MonitorChannel() As String
' returns the user selected channel to monitor
Dim Index As Long With lstChannel
Index = .ListIndex
If Index > 0 Then
MonitorChannel = Right$(.List(Index), 3)
Else
MonitorChannel = "Front Panel"
Exit Function
End If
End WithEnd FunctionPublic Sub InstrumentError(Instrument As VisaComLib.FormattedIO488)
Dim reply As String With Instrument
.WriteString "Syst:Error?"
reply = .ReadString
End With If Val(reply) <> 0 Then
MsgBox "Instrument Error: " & vbCrLf & reply, vbCritical
InstrumentError Instrument
End IfEnd Sub
Private Function isconnected() As Boolean
' determines if the instrument is connected, and
' gives a message if not
Dim result() As Variant
Dim oldTimeout As Long On Error GoTo connectError With Daq
oldTimeout = .io.Timeout
.io.Timeout = 1000
.WriteString "*IDN?"
result = .ReadList
.io.Timeout = oldTimeout
End With If InStr(1, result(1), "34970A", vbTextCompare) = 0 Then
GoTo WrongInstrumentError
End If isconnected = True Exit FunctionconnectError:
Daq.io.Timeout = 10000
MsgBox "Instrument not connected. Please check connections and use the Set I/O toolbar button to set the instrument connection."
isconnected = False
Exit Function
WrongInstrumentError:
MsgBox "Incorrect instrument: " & vbCrLf & _
"Expected 34970A " & vbCrLf & _
"Instrument discovered: " & result(1)
isconnected = False
End FunctionPrivate Sub cmdSetIO_Click()
' set the I/O address to the text box in case the
' user changed it.
' bring up the input dialog and save any changes to the
' text box
Dim mgr As VisaComLib.ResourceManager
On Error GoTo ioError m_ioAddress = InputBox("Enter the IO address of the Function Generator", "Set IO address", m_ioAddress) Set mgr = New VisaComLib.ResourceManager
Set Daq = New VisaComLib.FormattedIO488
Set Daq.io = mgr.Open(m_ioAddress)
Exit Sub
ioError:
MsgBox "Set IO error:" & vbCrLf & Err.DescriptionEnd Sub
完全不懂啊,编译出现错误
could not interpret I/O as single number
我的前提是你VB没有问题的话. 如果你VB也不过关, 那么还是花点钱请人做吧.