UOPEN Command

The UOPEN command opens a given file name to an mvBASIC file variable.

Format

UOPEN <path> [FOR {READWRITE|READ|WRITE}] TO FileHandle THEN statement(s) ELSE statement(s)

Parameter(s)

path

File expressed by the valid path name, within quotes.

FileHandle

Must be used for all future references to the file.

Description

The file pointer is positioned at the beginning of the file. The path points to a path naming a file. If an error occurs or the file does not exist, the ELSE clause executes.

One reason that the UOPEN command may fail is that the user attempting to open the file does not have the necessary permissions. For example, if the file contains confidential information that the mvBase user is not authorized to read, the UOPEN command does not open the file. The ELSE clause executes instead.

FileHandle is a variable that is returned from UOPEN and must be used for subsequent accesses to this file. FileHandle is the file descriptor of the file on the host system. If the file cannot be opened, the ELSE clause executes.

Example

FILEDES1 contains the file descriptor that allows the user to access the file \books\chap4.txt. The file is opened for READ only. Any attempt to write to the file using this file descriptor results in an error.

UOPEN “c:\books\chap4.txt” FOR READ TO FILEDES1 ELSE STOP

This statement opens the file chap4.txt located in the current directory. FILEDES2 contains the file descriptor necessary to open the file chap4.txt. The file is opened for WRITE only. If the UREAD command is used, an error results. If the file cannot be opened for any reason, the message in the ELSE clause displays.

UOPEN “chap4.txt” FOR WRITE TO FILEDES2 ELSE PRINT “CAN NOT OPEN FILE!”

The next statement opens the file chap4.txt located in the parent directory of the current directory. If the file can be opened for reading and writing, FILEDES3 contains the file descriptor allowing access to the file. If an error occurs, the ELSE clause executes.

UOPEN “..\chap4.txt” FOR READWRITE TO FILEDES3 ELSE STOP

The last statement opens the file chap4.txt for reading and writing. After the file is opened, FILEDES4 contains the file descriptor that allows access to the file chap4.txt. If an error occurs, the ELSE clause executes.

UOPEN “chap4.txt” TO FILEDES4 ELSE STOP

See Also

O/S Interoperability Commands

UCLOSE Command

UCREATE Command

UDELETE Command

UERROR Function

UEXECUTE Command

ULOCK Command

ULSEEK Function

UMESSAGE Command

UREAD Command

UREADLINE Function

USYSTEM Function

UWAITFOR Command

UWRITE Command