Put Statement

Description

Writes from a variable to a disk file.

Syntax

Put [#]filenumber,[recnumber],varname

The Put statement syntax has these parts:

Part

Description

filenumber

Any valid file number.

recnumber

Record number (Random mode files) or byte number (Binary mode files) at which writing begins.

varname

Name of variable containing data to be written to disk.


Remarks

The first record/byte in a file is at position 1, the second record/byte is at position 2, and so on. If you omit recnumber, the next record or byte (the one after the last Get or Put statement or the one pointed to by the last Seek function) is written. You must include delimiting commas, for example:


Put #4,,FileBuffer

For files opened in Random mode, the following rules apply:

For files opened in Binary mode, all of the Random rules apply except that:

See Also

Get Statement, Open Statement, VarType Function.

Example

This example uses the Put statement to write data to a disk file. Five records of the user-defined type Record are written to the file.


' Define user-defined type.
Type Record
    ID As Integer
    Name As String * 20
End Type
Dim MyRecord As Record    ' Declare variable.
' Open file for random access.
Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
For RecordNumber = 1 To 5    ' Loop 5 times.
    MyRecord.ID = RecordNumber    ' Define ID.
    MyRecord.Name = "My Name" & RecordNumber    ' Create a string.
    Put #1, RecordNumber, MyRecord    ' Write record to file.
Next RecordNumber
Close #1    ' Close file.