I am setting up a system using the Keithley 7065 Hall Effect card and am using the Keithley 2400 Sourcemeter, 2000 Multimeter, 6514 Electrometer, and 7001 Switch System. I have a program in VB6 that is attempting to measure the resistivity of a sample by measuring voltages and currents. The program works successfully (it measures the resistivity), but if I try to run it again (even after exiting the program), it returns an error "Run-time error '5': Invalid procedure call or argument"
The line it is crashing on is
current = 5 * (1 / Sqr(200 * ur))
I don't understand why it works and then doesn't. Sometimes (but rarely) if I keep trying to run it again it works without that error. Most of the time, though, I have to restart the computer before it works again.
This code is being written in VB6. I had to communicate with the instruments using device-level code (e.g., ibrd, ibwrt).
Below is the subroutine with the line that causes the error:
Private Sub testCurrent()
Dim current, ur, uvolt, ucurr, sumr, sumvolt, sumcurr As Double
Dim meas_volt As String
Dim meas_curr As String
numaverages = 25
Dim data() As Double
'using a test current of 1 milliampere to determine cross point resistance for power consumption limitation
Call send(sm, ":SOUR:CURR:LEV " + Str(0.001), status)
Call send(sm, ":SENS:FUNC 'CURR'", status)
Call send(sm, ":FORM:ELEM CURR", status)
'apply current to I13 and measure V13 determine R
Call send(ss, ":CLOS (@" + getCrossPointsInit + ")", status)
Call send(sm, ":OUTP:STAT ON", status)
ReDim data(2, numaverages)
For I = 0 To UBound(data, 2)
DoEvents
Call send(mm, ":MEAS:VOLT?", status)
Call GetReply(meas_volt, CInt(255), CInt(1), mm, status)
Call send(sm, ":MEAS:CURR?", status)
Call GetReply(meas_curr, CInt(255), CInt(1), sm, status)
DoEvents
data(0, I) = val(meas_volt)
data(1, I) = val(meas_curr)
data(2, I) = data(0, I) / data(1, I)
Next I
Call send(sm, ":OUTP:STAT OFF", status)
Call send(ss, ":OPEN ALL", status)
sumvolt = 0: sumcurr = 0: sumr = 0
For I = 0 To UBound(data, 2)
sumvolt = sumvolt + data(0, I)
sumcurr = sumcurr + data(1, I)
sumr = sumr + data(2, I)
Next I
'calculate average mu (u)
uvolt = sumvolt / (numaverages)
ucurr = sumcurr / (numaverages)
ur = sumr / (numsamples + 1)
current = 5 * (1 / Sqr(200 * ur)) 'Power dissipated should be less than 5 mw. ERROR HERE
Call send(sm, ":SOUR:CURR:LEV " + Str(current), status)
End Sub