Examples: Put statement

Type PersonRecord
   empNumber As Integer
   empName As String * 20
End Type
Dim fileNum As Integer
Dim fileName As String
Dim rec As PersonRecord
fileNum% = FreeFile()
fileName$ = "data.txt"
' First, open a random file with a record length equal to
' the size of the records to be stored.
Open fileName$ For Random As fileNum% Len = Len(rec)
rec.empNumber% = 123
rec.empName$ = "John Smith"
Put #fileNum%, 1, rec       ' Write this record at position 1.
rec.empNumber% = 456
rec.empName$ = "Jane Doe"
Put #fileNum%, 2, rec       ' Write this record at position 2.
rec.empNumber% = 789
rec.empName$ = "Jack Jones"
Put #fileNum%, , rec        ' Write at current position (3).
Seek fileNum%, 1            ' Rewind file to beginning.
Do While Not EOF(fileNum%)
   ' Get a record, print it out. 
   ' Get advances the file position to the next
   ' record automatically.
   Get #fileNum%, , rec
   Print rec.empNumber%, rec.empName$
Loop
' Output:
' 123         John Smith
' 456         Jane Doe
' 789         Jack Jones  
Close fileNum%              ' Close the file.