Specifications

128 Chapter 9
Saving and Recalling Files
Sample Program
Sample Program
Example 9-1 shows a sample program that demonstrates how to save data to a file. You can
find the source file of this program, named file_sav.bas, on the sample program disk.
The sample program saves the selected type of data to the specified target file.
The program is described in detail below:
Line 40 Sets the GPIB address.
Lines 60 to 70 Retrieves the list/single-point (0/1) measurement setting and stores the
setting into the List_stat variables.
Lines 80 to 90 Counts the data segments for statistical analysis that are residing on
the volatile memory and stores the count into the Point variable.
Line 110 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.
Lines 130 to 310 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.
Line 320 Converts the entered value into an integer and stores it into the Content
variable.
Line 330 If Content is not within the valid range, the program returns the user to
the entry start line.
Lines 360 to 630 Determines the file extension based on Content and stores the
extension into the Extension$ variable. If the extension is “.csv,”
determines the second parameter for the command to save and stores
the parameter into the Par$ variable.
Line 650 Passes control to a subprogram named 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.
Lines 670 to 730 Saves the data and displays the name of the target file.
The Inp_file_name subprogram in lines 790 to 900, which is used to enter a save filename,
is described below.
Line 810 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 entering the target file
name.
Lines 830 to 850 Prompts the user to enter the target file name. The program does not
continue until the user actually enters the file name.
Lines 860 to 870 Displays the entered file name and waits for a confirmation entry (y/n
key).
Line 880 Returns to the start line of input if any key other than the y key is
pressed in response to line 870.