Liberty BASIC Help Online |
OPEN
OPEN device FOR purpose AS #handle {LEN = n}
Description:
The OPEN command opens communication with a device, which can be a disk file, a window, a dynamic link library or a serial communications port. The command must be told what to open, for what purpose, and a descriptive, unique name or "handle" must be assigned to it so that other functions can access the open device. Handles must always begin with "#" to identify them as such and to distinguish them from other variables. The details for using the OPEN statement are shown below. It will be necessary to refer to the individual topics for complete explanations for using OPEN with the various devices.
Note: Any device that is opened during the normal operation of the program must be closed before program execution is finished. See CLOSE Changing the handle of a device dynamically at runtime can be accomplished with the MAPHANDLE command.
device
The device to be opened may be one of the following:
file
If the device to be opened is a file, the device parameter must be a valid disk filename. This may be expressed as a string variable, or as a literal text expression enclosed in quotes. For more on coding file specifications, see Path and Filename.
purpose
Files may be opened for the purpose of INPUT, OUTPUT, APPEND, RANDOM or BINARY access. The final {LEN=n} parameter applies to files opened for RANDOM access. For more on opening files, please see File Operations.
usage:
open "c:\readme.txt" for input as #f
window
If the device to be opened is a window, the device parameter will become the caption of the window. The caption is the text contained on the titlebar of the window.
purpose
usage:
open "My Cool Program" for window_nf as #main
dynamic link library
A DLL (dynamic link library) must be opened before any calls can be made to the functions. If the device is a DLL the device parameter will be the disk filename of the DLL, enclosed in quotes. See CALLDLL.
purpose
The purpose is always "for DLL" when using OPEN with a dynamic link library.
usage:
open "c:\myprog\sample.dll" for DLL as #sample
or for Windows API calls:
open "user32" for DLL as #user32
serial communications port
The OPEN statement opens a serial communications port for reading and writing. The device parameter is the name of the port enclosed in quotes. The syntax looks like this:
OPEN "COMn:baud,parity,data stop{,options}" for random as #handle
purpose
The purpose is always "for random" when using OPEN to open a communications port. See " Open "Comn..."
Usage:
To open com port 2 at 9600 baud, 8 data bits, 1 stop bit, and no parity, use this line of code:
open "com2:9600,n,8,1" for random as #commHandle
The #handle is a unique name given to the