Put Statement

Writes data from a variable to a disk file.

Syntax

Put [#]filenumber, [recnumber], varname

The Put statement syntax has the following parts:

Part Description
filenumber Required. Any valid file number.
recnumber Optional. Record number (Random mode files) or byte number (Binary mode files) at which writing begins.
varname Required. Name of variable containing data to be written to disk.

Remarks

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

Put #4,,FileBuffer

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

Example

In this example the Put statement is used to write data to a file.

Dim sName as String*20, nRecordNumber   ' Declares variable.
' Opens file for Random access.
Open "TESTFILE" For Random As #1 Len = 21
For nRecordNumber = 1 To 5 ' Repeats the loop 5 times.
sName = "My Name " & nRecordNumber ' Creates a string.
Put #1, nRecordNumber, sName ' Writes record to file.
Next nRecordNumber

Close #1 ' Closes file.

See Also

Writing Data to a File, Get Statement, Open Statement, Seek Statement, VarType Function