Other topics about Sample Programs
This sample program demonstrates how to save data to a file. It saves the selected type of data to the specified target file.
See these topics for this programming:
Sub FileSave()
'This sample program saves the selected type of data to the specified target file
Dim File As String
Dim InpChar As String
Dim Extension As String
Dim Par As String
Dim listStat As Integer
Dim Point As Integer
Dim Content As String
Dim maxNo As Integer
Dim outString As String
Dim fileName As String
Dim ioMgr As VisaComLib.ResourceManager
Dim age4982x As VisaComLib.FormattedIO488
'Sets the GPIB address
Set ioMgr = New VisaComLib.ResourceManager
Set age4982x = New VisaComLib.FormattedIO488
Set age4982x.IO = ioMgr.Open("GPIB0::17::INSTR")
age4982x.IO.Timeout = 30000
'Retrieves the list/single-point(0/1) measurement setting and stores the
'setting into the listStat variables
age4982x.WriteString ":SOUR:LIST:STAT?"
listStat = age4982x.ReadNumber
'Counts the data segments for statistical analysis that are residing on
'the volatile memory and stores the count into the Point variable
age4982x.WriteString ":CALC:EXAM:MEM:POIN?"
Point = age4982x.ReadNumber
'Allows the user to return to the entry start line and re-enter the data if
'an error (such as an invalid entry) occurs while selecting the type of data
'to save
On Error GoTo Content_select
'Displays the list of items that can be saved and prompts the user to choose
'one of the items by typing in the appropriate number
Content_select:
'Display the list of items that can be saved and prompts the user to choose one
'of the items by typing in the appropriate number
outString = "## Save Content Selection ##" & vbCr & "Select Content" & vbCr & "1: State" & vbCr _
& "2: Screen" & vbCr & "3: Setup Table" & vbCr & "4: Comparator"
maxNo = 4
If listStat = 1 Then
outString = "## Save Content Selection ##" & vbCr & "Select Content" & vbCr & "1: State" & vbCr _
& "2: Screen" & vbCr & "3: Setup Table" & vbCr & "4: Comparator" & vbCr _
& "5: List Measurement Results"
maxNo = maxNo + 1
End If
If Point > 1 Then
outString = outString & vbCr & "" & (maxNo + 1) & " : Data for Statistical Analysis (ASCII)" & vbCr _
& "" & (maxNo + 2) & " : Data for statistical Analysis (Binary)"
maxNo = maxNo + 2
End If
outString = outString & vbCr & "Input 1 to " & maxNo
Content = InputBox(" " & outString)
If Content = "" Then End
Err.Clear
'If Content is not within the valid range, the program returns the user to
'the entry start line
If Val(Content) < 1 Or Val(Content) > maxNo Then
GoTo Content_select
End If
'Determine the file extension based on Content and stores the extension into
'the Extension variable. If the extension is ".csv", determine the second
'parameter for the command to save and store the parameter into the Par variable
Select Case Content
Case 1
Extension = ".sta"
Case 2
Extension = ".bmp"
Case 3
Extension = ".csv"
Par = "SET"
Case 4
Extension = ".csv"
Par = "COMP"
Case 5
Extension = ".csv"
If maxNo = 5 Or maxNo = 7 Then
Par = "LIST"
Else
Par = "LOG"
End If
Case 6
If maxNo = 7 Then
Extension = ".csv"
Par = "log"
Else
Extension = ".dta"
End If
Case 7
Extension = ".dta"
End Select
'Pass control to a subprogram called Inp_file_name, which lets the user
'input a file name without an extension, and then stores the returned
'file name into the File variable
Call Inp_file_name(File)
fileName = File & Extension
'fileName = """&fileName&"""
If Extension = ".csv" Then
age4982x.WriteString ":MMEM:STOR """ & fileName & """, " & Par
Else
age4982x.WriteString ":MMEM:STOR """ & fileName & """"
End If
MsgBox "## Done ##" & vbCr & "Save file name : " & File & Extension
End Sub
Public Sub Inp_file_name(Inp_name)
Dim InpChar As String
'Allow the user to return to the entry start line and re-enter the data
'if an error (such as invalid entry) occurs when entering the target
'file name
On Error GoTo Inp_start
Inp_start:
'Prompt the user to enter the target file name. The program does not
'continue until the user actually enters the file name
Inp_name = InputBox("## File Name Input##" & vbCr & "Input Save File Name (without Extension)" _
& vbCr & "Name?")
If Inp_name = "" Then End
'Display the entered file name and waits for confirmation entry (y/n key)
InpChar = InputBox("Input Name: " & Inp_name & vbCr & "OK? [Y/N]")
If InpChar = "" Then End
'Return to the start line of input if any key other than the y key is
'pressed in response
If UCase(InpChar) <> "Y" Then
GoTo Inp_start
End If
Err.Clear
End Sub