OPEN

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Window Handling

Description

Opens a window for use in a program. Three pieces of information (parameters) are needed to open the window - device, purpose, and handle.
Device - the window caption (title)
Purpose - window type
Handle - the window's unique identifier
See Window Types and Handle.
Any window which is OPENed must be CLOSEd before ending a program. See CLOSE and TRAPCLOSE.

Syntax

  1. open device for purpose as #handle

Example

' This statement will open a window of "Type Window" with a caption
' of "My First Window" and a handle of #1. The handle is used so
' other parts of the program can interact with this specific window.
    open "My First Window" for window as #1
    ' Notice that the caption is enclosed in quotes (").
    ' To make sure program ends properly, use 'trapclose':
    #1 "trapclose [quit]"
    wait
[quit]
    close #1
    end

Useful Procedures

' Place a useful function or sub using this keyword here

File Handling

Description

Similar to opening a window, opening a file requires three parameters - device, purpose and handle.
Device - a valid disk filename
Purpose - type of file access
Handle - the file's unique identifier
For purpose, see File Access Types. (Files can be opened for INPUT, OUTPUT, APPEND, RANDOM or BINARY access.)
A file which is OPENed must be CLOSEd before ending a program. See CLOSE.

Syntax

  1. open device for purpose as #handle

Example

' A file can be opened using a literal text expression for the device parameter:
    open "c:\readme.txt" for input as #f
    ' Notice that the literal reference must be enclosed in quotes (").

' or, the device parameter can be a string variable:
    open fileName$ for input as #f

Useful Procedures

' Place a useful function or sub using this keyword here

Serial Device Handling

Description

Opens a serial communications port for reading and writing. The required parameters are; baud, parity, data, and stop. Additional optional parameters can be included after the required parameters.
See also the Com buffer size variable, Com Error Handler, Com Error Description, Com Error Number and Com Port Number
As with the other devices, the port must be CLOSEd when done and before ending the program.

Syntax

  1. open "COMn:baud,parity,data,stop,flags" for random as #handle

Hints

Default settings: DTR disabled, XON/XOFF disabled, binary transfer mode

Available baud rates: 75 110 150 300 600 1200 2400 1800 2400 4800 9600 19200 38400 57600 115200

Parity Flags Data Size Stop Size Additional Flags
Flag Meaning bits long bits long Flag Meaning
N No parity 5 1 CSn CTS timeout, default 1000ms, 0ms = off
E Even parity 6 2 DSn DSR timeout, default 1000ms, 0ms = off
O Odd parity 7 PE Enable parity checks
S Space parity 8 RS Disable RTS
M Mark parity

Example

' 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
    ' Notice that the device reference is enclosed in quotes (").

Useful Procedures

' Place a useful function or sub using this keyword here