Saving Files

Other topics about Sample Programs

Overview

The sample program demonstrates how to save a file. This program saves selected content on a file with a specified name.

See Saving and Recalling File for this programming.

Sample Program in Excel VBA

Sub File_Save()

    ' Declare two string variables for file name and file type

    Dim File_Name As String

    Dim File_Type As String

    Dim defrm As Long

    Dim vi As Long

    Const TimeOutTime = 10000

    ' Check whether file name textbox is empty or not

    If TextBox1.Text <> "" Then

        File_Name = Trim(TextBox1.Text)

        File_Type = Trim(frmFileSave.ComboBox1.Value)

    ' Open connection to the E5071C

        Call viOpenDefaultRM(defrm)

        Call viOpen(defrm, "GPIB0::18::INSTR", 0, 0, vi)

        Call viSetAttribute(vi, VI_ATTR_TMO_VALUE, TimeOutTime)

        Select Case File_Type

            Case "1: State (State only)"

                Call viVPrintf(vi, ":MMEM:STOR:STYP STAT" + vbLf, 0)

                Call viVPrintf(vi, ":MMEM:STOR """ & File_Name & ".sta""" + vbLf, 0)

            Case "2: State (State & Cal)"

                Call viVPrintf(vi, ":MMEM:STOR:STYP CST" + vbLf, 0)

                Call viVPrintf(vi, ":MMEM:STOR """ & File_Name & ".sta""" + vbLf, 0)

            Case "3: State (State & Trace)"

                Call viVPrintf(vi, ":MMEM:STOR:STYP DST" + vbLf, 0)

                Call viVPrintf(vi, ":MMEM:STOR """ & File_Name & ".sta""" + vbLf, 0)

            Case "4: State (State & Cal & Trace)"

                Call viVPrintf(vi, ":MMEM:STOR:STYP CDST" + vbLf, 0)

                Call viVPrintf(vi, ":MMEM:STOR """ & File_Name & ".sta""" + vbLf, 0)

            Case "5: State (Trace Data (CSV))"

                Call viVPrintf(vi, ":MMEM:STOR:FDAT """ & File_Name & ".csv""" + vbLf, 0)

            Case "6: State (Screen)"

                Call viVPrintf(vi, ":MMEM:STOR:IMAG """ & File_Name & ".bmp""" + vbLf, 0)

            Case Else

                msgbox "Error in code"

        End Select

    Call viClose(defrm)

    Else

        msgbox "Please enter a filename"

    End If

End Sub

Sample Program in HT Basic (file_sav.htb)

10 DIM File$[300],Inp_char$[30]

20 INTEGER Content

30 CLEAR SCREEN

40 ASSIGN @Agte507x TO 717

50 !

60 ON ERROR GOTO Content_select

70 Content_select: !

80 PRINT "## Save Content Selection ##"

90 PRINT "Select Content"

100 PRINT " 1: State (State only)"

110 PRINT " 2: State (State & Cal)"

120 PRINT " 3: State (State & Trace)"

130 PRINT " 4: State (State & Cal & Trace)"

140 PRINT " 5: Trace Data (CSV)"

150 PRINT " 6: Screen"

160 PRINT ""

170 PRINT "Input 1 to 6"

180 INPUT "Number?",Inp_char$

190 Content=IVAL(Inp_char$,10)

200 IF Content<1 OR Content>6 THEN Content_select

210 OFF ERROR

220 !

230 CALL Inp_file_name(File$)

240 !

250 SELECT Content

260 CASE 1

270 OUTPUT @Agte507x;":MMEM:STOR:STYP STAT"

280 OUTPUT @Agte507x;":MMEM:STOR """&File$&".sta"""

290 CASE 2

300 OUTPUT @Agte507x;":MMEM:STOR:STYP CST"

310 OUTPUT @Agte507x;":MMEM:STOR """&File$&".sta"""

320 CASE 3

330 OUTPUT @Agte507x;":MMEM:STOR:STYP DST"

340 OUTPUT @Agte507x;":MMEM:STOR """&File$&".sta"""

350 CASE 4

360 OUTPUT @Agte507x;":MMEM:STOR:STYP CDST"

370 OUTPUT @Agte507x;":MMEM:STOR """&File$&".sta"""

380 CASE 5

390 OUTPUT @Agte507x;":MMEM:STOR:FDAT """&File$&".csv"""

400 CASE 6

410 OUTPUT @Agte507x;":MMEM:STOR:IMAG """&File$&".bmp"""

420 END SELECT

430 !

440 END

450 !=============================================

460 ! File Name Input Function

470 !=============================================

480 SUB Inp_file_name(Inp_name$)

490 DIM Inp_char$[9]

500 ON ERROR GOTO Inp_start

510 Inp_start: !

520 PRINT "## File Name Input ##"

530 PRINT "Input Save File Name (without Extension)"

540 INPUT "Name?",Inp_name$

550 PRINT "Input Name: "&Inp_name$

560 INPUT "OK? [Y/N]",Inp_char$

570 IF UPC$(Inp_char$)<>"Y" THEN Inp_start

580 OFF ERROR

590 SUBEND