Writes data from a variable to a disk file.
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Short, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Integer, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Single, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Double, _ RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Decimal, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Byte, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Boolean, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As Date, _ Optional RecordNumber As Integer = -1 _ )
-or-
Public Overloads Sub FilePut( _ FileNumber As Integer, _ Value As System.Array, _ Optional RecordNumber As Integer = -1, _ Optional ArrayIsDynamic As Boolean = False _ )
-or-
Public Overloads Sub FilePut ( FileNumber As Integer, Value As String, _ Optional RecordNumber As Integer = -1, Optional StringIsFixedLength As Boolean = False )
Exception type | Error number | Condition |
---|---|---|
63 | RecordNumber < 1 and not equal to -1. | |
52 | FileNumber does not exist. | |
54 | File mode is invalid. |
FilePut is only valid in Random and Binary mode.
Data written with FilePut is usually read from a file with FileGet.
The first record or byte in a file is at position 1, the second record or byte at position 2, and so on. If you omit RecordNumber, the next record or byte after the last FileGet or FilePut function or pointed to by the last Seek function is written.
The StringIsFixedLength argument controls whether the function interprets strings as variable or fixed length. FilePut does not write the length descriptor when the argument is True. If you use StringIsFixedLength = True with FilePut, you will need to do the same with FileGet, and also make sure the string is initialized to the length expected.
For files opened in Random mode, the following rules apply:
Dim MyArray(4,9) As Integer
For files opened in Binary mode, all of the Random mode rules apply, except:
Dim hellow As String = "Hello World" FilePut(1,hellow)
This example uses the FilePut function to write data to a file. Five records of the structure Person
are written to the file.
Structure Person
Public ID As Integer
Public Name As String
End Structure
Sub WriteData()
Dim MyRecord As Person
Dim recordNumber As Integer
' Open file for random access.
FileOpen(1, "C:\TESTFILE.txt", OpenMode.Binary)
For recordNumber = 1 To 5 ' Loop 5 times.
MyRecord.ID = recordNumber ' Define ID.
MyRecord.Name = "My Name" & recordNumber ' Create a string.
FilePut(
1, MyRecord) ' Write record to file.
Next recordNumber
FileClose(1)
End Sub
FileGet Function | FileOpen Function | Seek Function |