Ok first off im using the script editor for a job at work as a little proof of concept for a customer. He doesnt want to install any software etc so im attempting in script for him via excel.
I went to vbforums but their nospam thing is ridiculous and doesnt work.
So im hopeing you guys can help.
Right Senario.
Products on a test line, comes to the end an Agilent scope performs a test and logs its results and saves as a text file!
For every text file i would like the name to change. so say its testing a transistor, is it possible to name the text files each time the test is run transistor1.txt then transistor2.txt
In order to get this i assume the script must loop, so can i get my script to loop and pause, Like jsut have one big button that runs the test.
Also i have no idea how you get the Text box to input names, like at the start the user needs to enter what line hes on and what test hes performing.
Any help with this is rgeatly appriciated guys :)
I include my script bellow for evaluation.
Option Explicit
Public myMgr As VisaComLib.ResourceManager
Public myScope As VisaComLib.FormattedIO488
Public varQueryResult As Variant
Public strQueryResult As String
Sub Main()
' Create the VISA COM I/O resource.
Set myMgr = New VisaComLib.ResourceManager
Set myScope = New VisaComLib.FormattedIO488
'Configure LAN conection
Set myScope.IO = myMgr.Open("TCPIP0::tim5.britain.agilent.com::inst0::INSTR")
Initialize
Capture
End Sub
Private Sub Initialize()
'Clear the interface
myScope.IO.Clear
'Default the Scope
myScope.WriteString "*RST"
'Set AutoScale
myScope.WriteString ":AUTOSCALE"
'Set the Vertical range
myScope.WriteString ":CHANNEL1:RANGE 8"
' Set the time range
myScope.WriteString ":TIM:RANG 2e-3"
' Set reference to center.
myScope.WriteString ":TIMEBASE:REFERENCE CENTER"
End Sub
Private Sub Capture()
' Declerations
Dim Frequency As String
Dim Time As String
Dim SetDate As String
Dim strPath As String
Dim AssemTyp As String
Dim AssemSerial As String
Dim TestType As String
Dim ProStep As String
Dim Amplitude As String
Dim AvVolt As String
myScope.WriteString ":SYSTem:TIME?"
varQueryResult = myScope.ReadString
strPath = "c:\scope\config\Data.txt" //Would like to increment with every run! Close #1 ' If #1 is open, close it.
' Open file for output.
Open strPath For Output Access Write Lock Write As #1
myScope.WriteString "*IDN?"
varQueryResult = myScope.ReadString
Write #1, , "Instrument ID: " + varQueryResult + vbCrLf
ProStep = "step 1" //[ These i would like user text input for.] Write #1, , "Process Step: " + ProStep + vbCrLf
TestType = "Frequencey Test" //[ These i would like user text input for.] Write #1, , "Test Type: " + TestType + vbCrLf
AssemTyp = "Malaysia 1" //[ These i would like user text input for.] Write #1, , "Assembly Name: " + AssemTyp + vbCrLf
AssemSerial = "Mlys01452203" //[ These i would like user text input for.] Write #1, , "Assembly Serial No: " + AssemSerial + vbCrLf
myScope.WriteString ":SYSTem:TIME?"
Time = myScope.ReadString
Write #1, , "Time: " + Time + vbCrLf
myScope.WriteString ":SYSTem:DATE?"
SetDate = myScope.ReadString
Write #1, , "DATE: " + SetDate + vbCrLf
'Test for frequency above 1KHz
myScope.WriteString ":MEASURE:FREQUENCY?"
Frequency = myScope.ReadNumber
Write #1, , "Frequency: " + FormatNumber(Frequency / 1000, 4) + " kHz"
If Frequency > 1000 Then Write #1, , "Result: Pass" Else: Write #1, , "Result: Fail" + vbCrLf
'Test for amplitude above 1V
myScope.WriteString ":MEASURE:VAMP?"
Amplitude = myScope.ReadNumber
Write #1, , "Amplitude: " + Amplitude
If Amplitude > 1 Then Write #1, , "Result: Pass" Else: Write #1, , "Result: Fail" + vbCrLf
'Test for Average Voltage above 0.5V
myScope.WriteString ":MEASURE:VAV?"
AvVolt = myScope.ReadNumber
Write #1, , "Average Voltage: " + AvVolt
If AvVolt > 0.5 Then Write #1, , "Result: Pass" Else: Write #1, , "Result: Fail"
Close #1
End Sub
<message edited by Nutkin on Tuesday, November 04, 2008 12:14 AM>