Example:

  1. ' The following example writes data to a test file and reads it back.

    Sub Main ()

    1. Dim I, FNum, FName' Declare variables.

      For I = 1 To 3

      1. FNum = FreeFile' Determine next file number.

        FName = "TEST" & FNum

        Open FName For Output As FNum' Open file.

        Print #I, "This is test #" & I' Write string to file.

        Print #I, "Here is another ";"line";I

      Next I

      Close' Close all files.

    End Sub

     

    Sub Main ()

    1. Dim FileData, Msg, NL' Declare variables.

      NL = Chr(10) ' Define newline.

      Open "TESTFILE" For Output As #1' Open to write file.

      Print #2, "This is a test of the Print # statement."

      Print #2' Print blank line to file.

      Print #2, "Zone 1", "Zone 2"' Print in two print zones.

      Print #2, "With no space between" ;"." ' Print two strings together.

      Close

      Open "TESTFILE" for Input As #2' Open to read file.

      Do While Not EOF(2)

      1. Line Input #2, FileData' Read a line of data.

        Msg = Msg & FileData & NL' Construct message.

        MsgBox Msg

      Loop

      Close' Close all open files.

      MsgBox "Testing Print Statement"' Display message.

      Kill "TESTFILE"' Remove file from disk.

    End Sub