Current Help System: PC-DMIS BASIC (View Core Help)

### File I/O Examples

Sub Main

Open "TESTFILE" For Input As #1 ' Open file.

Do While Not EOF(1) ' Loop until end of file.

Line Input #1, TextLine ' Read line into variable.

Print TextLine ' Print to Debug window.

Loop

Close #1 ' Close file.

End Sub

Sub test

Open "MYFILE" For Input As #1 ' Open file for input.

Do While Not EOF(1) ' Check for end of file.

Line Input #1, InputData ' Read line of data.

MsgBox InputData

Loop

Close #1 ' Close file.

End Sub

Sub FileIO_Example()

Dim Msg ' Declare variable.

Call Make3Files() ' Create data files.

Msg = "Several test files have been created on your disk. "

Msg = Msg & "Choose OK to remove the test files."

MsgBox Msg

For I = 1 To 3

Kill "TEST" & I ' Remove data files from disk.

Next I

End Sub

Sub Make3Files ()

Dim I, FNum, FName ' Declare variables.

For I = 1 To 3

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