Part | Description | |
pathname | Required. String expression that specifies a file name — may include directory or folder, and drive. | |
mode | Required. Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access. | |
access | Optional. Keyword specifying the operations permitted on the open file: Read, Write, or Read Write. | |
lock | Optional. Keyword specifying the operations permitted on the open file by other processes: Shared, Lock Read, Lock Write, and Lock Read Write. | |
filenumber | Required. A valid file number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number. | |
reclength | Optional. Number less than or equal to 32,767 (bytes). For files opened for random access, this value is the record length. For sequential files, this value is the number of characters buffered. |
Open "TESTFILE" For Input As #1
' Close before reopening in another mode.
Close #1
This example opens the file in Binary mode for writing operations only.
Open "TESTFILE" For Binary Access Write As #1
' Close before reopening in another mode.
Close #1
The following example opens the file in Random mode. The file contains records of the user-defined type Record.
Type Record ' Define user-defined type.
ID As Integer
Name As String * 20
End Type
Dim MyRecord As Record ' Declare variable.
Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
' Close before reopening in another mode.
Close #1
This code example opens the file for sequential output; any process can read or write to file.
Open "TESTFILE" For Output Shared As #1
' Close before reopening in another mode.
Close #1
This code example opens the file in Binary mode for reading; other processes can't read file.
Open "TESTFILE" For Binary Access Read Lock Read As #1