Syntax:
Open "strFileName" [For Mode] [AccessRestriction]
[LookType] As [#]intFileNum [Len = intRecord/reclength]
Note:
Open "aFile.txt" as #1
The above opens a file named aFile.txt in Ranom Mode with the file handler of 1
Open
You must open a file before any I/O operation can be performed on it. Open allocates a buffer for I/O to the file and determines the mode of access to use with the buffer.The Open statement associates a number to a handle also called a channel. Once the association exist, the program uses the number for file access of both input and output: I/O is depended on what mode value is used (see [For Mode]).
"strFileName"
Required PathName String expression that specifies a file name. It may include directory or folder, and drive.The strFileName (PathName) is a file that is opened to be used for input/output from/to a disk drive. Once it is Open, the program refers to it via it's file handler number, and not it's name.
If the file specified by the pathname (strFileName) doesn't exist, it is created when a file is opened for Append, Binary, Output, or Random modes.
[For Mode]
Mode is a special keyword, shown in the chart below, that indicates the files access mode. If unspecified, the file is opened for Random access.When you open a sequential file, you can't change its data. You can either read it (and store it to another file) or overwrite the entire file with the new data. To do so, you must open the file for Input, read its data, and then close the file. To overwrite it, open it again (this time for output) and save the new data to it.
Use Append if you don't want to overwrite an existing file but want to add to the end of it.
Keyword (Mode) Description Append Sequential File Type - Opens a file number to a file for sequential output, beginning at the end of the file if the file exists. If the file doesn't exist, VB creates the file. Append never overwrites existing file data. Binary Binary File Type - Opens a file number to a file for binary data access. In Binary mode, you can access a file at the byte level, meaning that you can write and read individual bytes to and from the file. The Len clause is ignored if mode is Binary. Input Sequential File Type - Opens a file number to a file for sequential input, starting at the beginning of the file. Data is read in the same order it was sent out the file.
Read - Syntax: Input # intFileNumber, Variable1] _
  [, Variable2][, VariableN]Output Sequential File Type - Opens a file number to a file for sequential output, starting at the beginning of the file. If the file doesn't exist when you issue the Open statement, Visual Basic creates the file, otherwise, VB overwrites the file.
Write / Print - Syntax: Write # intFileNumber, Variable1] _
  [, Variable2][, VariableN]Print # intFileNumber, Variable1] _
  [, Variable2][, VariableN]Random Random Access File Type - Opens a file number to a file for random read and write access. This mode allows data to be read from and writen to a file at any specific record boundary.
Reads a file Get [#]intFileNumber, [intRecNum,] variable
Writes a file Put [#]intFileNumber, [intRecNum,] variable
[AccessRestriction]
If the file is already opened by another process and the specified type of access is not allowed, the Open operation fails and an error occurs.
Read Read-Only access lets users see the contents of the file but leaves them unable to modify it Write Write access lets users modify the file Read Write Read Write access lets users do both read and modify the file.
[LockType]
Shared Shared lets all users access the file simultaineously Lock Read Lock read Locks the file so that only the person with the file open for reading can access the file Lock Write Lock Write Locks the file so that only the person who has the file open for write access can write to the file Lock Read Write Lock Read Write locks the file from all users except the one who has the file open for read and write acess.
As [#]intFileNum
A valid file number (handle) in the range of 1 to 511 must be assigned to open a file and reference that file.Locating a Free File Number with the FreeFile() Function
The FreeFile()function can be used to determine the next available file number.
Example:
intFileNumber = FreeFile Open "AccPay.Dat" for Output as intFileNumber