WOpen Statement
Opens a file for writing.
Syntax
WOpen fileName As #fileNumber
.
.
Close #fileNumber
Parameters
- fileName
- Specify a string containing the path and file name. If path is omitted, the file in the current directory is specified. See ChDisk for the details.
- fileNumber
- Specify an integer value from 30 to 63 or an expression.
Description
Opens the specified file using the specified fileNumber. This statement is used to open and write data to the specified file. (To append data, refer to the AOpen explanation.)
If the specified filename does not exist on the disks current directory, WOpen creates the file and writes to it. If the specified filename exists, WOpen erases all of the data in the file and writes to it.
fileNumber identifies the file while it is open and cannot be used to refer to a different file until the current file is closed. fileNumber is used by other file operations such as Print#, Write, Seek, and Close.
Close closes the file and releases the file number.
It is recommended that you use the FreeFile function to obtain the file number so that more than one task are not using the same number.
Notes
A network path is available.
File writing is buffered.
The buffered data can be written with Flush statement. Also, when closing a file with Close statement, the buffered data can be written.
See Also
AOpen, BOpen, Close, Print#, ROpen, UOpen, FreeFile
WOpen Statement Example
Integer fileNum, i, j
fileNum = FreeFile
WOpen "TEST.DAT" As #fileNum
For i = 0 To 100
Print #fileNum, i
Next i
Close #fileNum
fileNum = FreeFile
ROpen "TEST.DAT" As #fileNum
For i = 0 to 100
Input #fileNum, j
Print "data = ", j
Next i
Close #fileNum