• Aucun résultat trouvé

Purpose: Searches for the first occurrence of string y$ in x$

and returns the position at which the match is found.

The optional offset n sets the position for starting the search in x$

Versions: Cassette

***

can be string variables, string expressions, or string constants.

If n>LEN(x$), or if x$ is null, or if y$ cannot be found, INSTR returns

.0.

If y$ is null, INSTR returns n (or 1 if n is not specified).

If n is out of range, an Illegal function call error is returned.

Example: This example searches for the string "B" within the string "ABCDEB". When the string is searched from the beginning, "B" is found at position 2; when the search starts at position 4, "B" is found at position 6.

10 A$

=

"ABCDEB"

20 B$ = "B11

INT

Function

Purpose: Returns the largest integer that is less than or equal to x.

Versions: Cassette

***

Format: v

=

INT(x) Disk

***

Advanced

***

Remarks: x is any numeric expression.

Compiler

***

This is called the "floor" function in some other programming languages.

See also "FIX" and "CINT" functions. (They also return integer values.)

Example: This example shows how INT truncates positive integers, but rounds negative numbers upward (in a negative direction).

PRINT INT(45.67) 45

PRINT INT(-2.89) -3

IOCTL

Statement

Purpose: Allows BASIC to send a control data string to a device driver anytime after the driver has been OPENed.

Not valid for BASIC releases earlier than 3 .

.0.

Versions: Cassette Disk Advanced Compiler

Format:

Remarks:

*** ***

IOCTL [#}filenum,string

filenum is the file number for the device driver.

string is a string expression containing the control data.

BASIC's file I/O system allows you to create and install your own device drivers. The IOCTL statement and the IOCTL$ function send control data to and read data from your device driver.

An IOCTL command string can be up to 255 bytes long. Multiple commands within the string can be separated by semicolons:

You define the content and format of the control data string. The possible commands are determined by the characteristics of the driver installed.

IOCTL

Statement

Example: Initially, character device drivers for LPTl:, LPT2:, and LPT3: are installed, but they can be replaced. If you install a driver called LPT 1 to replace LPT 1: and that driver is able to set page length, an IOCTL command string to set or change the page length might be:

IPLn" (where n is the new page length).

You can then open the new LPT 1 driver and set the page length with:

OPEN ILPTl" FOR OUTPUT AS #1 IOCTL #1, IPL6(J"

You could, for instance, write a device driver that controls a monitor and is capable of setting the mode of the screen to color and also capable of setting the width of the screen. For example:

OPEN "OPT" FOR OUTPUT AS #2 IOCTL #2, "CL:W4(J"

Assuming that your new driver accepts a command called "CL" to change the screen to color and a command called "Wn" to set the width of the screen, the previous example passes those commands to your driver and causes the screen to respond.

Note: For related information, see "IOCTL$

Function" in this manual, "Device Drivers" in the BASIC Handbook, and the device driver section of Disk Operating System Technical Reference.

IOCTL$

Function

Purpose: Reads a control data string from a device driver that is open.

Not valid for BASIC releases earlier than 3 .

.0.

Versions: Cassette Disk Advanced Compiler

Format:

Remarks:

*** . ***

v$

=

IOCTL$([#l!ilenum)

filenum is the number of the file open to the device.

The IOTCL$ function can be used to get acknowledgment that an IOCTL command has succeeded or failed. It can also be used to get device configuration information, such as device width.

Example: This example checks to see if control data was successfully received.

10 OPEN "COM" AS #1 20 IOCTL #1, ISW132;GW"

30 IF IOCTL$(1) = "13211

THEN PRINT "WIDTH SET SUCCESSFULLY II If the device driver "COM" returns a value not equal to 132 from the IOCTL$ request, your command was not processed successfully and you should check for errors. If a device failure occurs,

KEY

Statement

Putpose: Sets or displays the soft keys.

Versions: Cassette

***

Disk

***

Advanced

***

Compiler (**)

Format: KEY ON

KEY OFF KEY LIST KEY n, x$

KEY n, CHR$(KBflag) and CHR$(scan code) (For Advanced BASIC 2.0 and later releases.)

Remarks: KEY ON causes the soft key values to be displayed on the 25th line. When the width is 4,e), 5 of the 1.0 soft keys are displayed. When the width is 8.0, all 1.0 are displayed. In either width, only the first 6 characters of each value are displayed.

KEY OFF erases the soft key display from the 25th line, making that line available for program use. It does not disable the function keys.

After turning off the soft key display with KEY OFF, you can use LOCATE 25,1 followed by PRINT to display anything you want on the bottom line of the screen. Information on line 25 is not scrolled, as are lines 1 through 24.

KEY

Statement

KEY LIST lists all 1.0 soft key values on the screen.

All 15 characters of each value are displayed.

KEY n,x$ allows you to set each function key to automatically type any sequence of characters. ON is the default state for the soft key display.

n is the function key number in the range 1 to 1.0.

x$ is a string expression that is assigned to the key. (Remember to enclose string constants in quotation marks.)

The value of a function key n is reassigned the value of the string x$. If the value entered for n is not in the range 1 to 1.0, an Illegal function call error occurs.

The previous key string assignment is retained. x$

can be 1 to 15 characters in length. If it is longer than 15 characters, only the first 15 characters are assigned.

Assigning a null string to a soft key disables the function key as a soft key.

When a soft key is pressed, the INKEY$ function returns one character of the soft key string each time it is called. The first character is binary zero, the second is the key scan code, as listed in Appendix D,

"ASCII Character Codes."

KEY

Statement

There are also six definable key traps. With this capability, you can trap any Ctrl, Shift, or super-shift key. (For Advanced BASIC 2;,0 and later releases.) These additional keys are defined by the statement:

KEY n,CHR$(KBflag)+CHR$(scan code)

n

KBflag

is a numeric expression in the range 15 to 2,0.

is a mask for the latched keys. The appropriate bit in KBflag must be set in order to trap a key that is shifted, Alt-shifted, or Ctrl-shifted. The KBflag values in hex are :

Caps Lock &H,0-Caps Lock is not active.

Caps Lock &H4,0-Caps Lock is active.

Num Lock &H,0-Num Lock is not active.

Num Lock &H2,0-Num Lock is active.

AU &H,08-AL T key is pressed.

Ctrl &H,04-Control key is pressed.

Left Shift &H,02-Left Shift key is pressed.

Right Shift &H,01-Right Shift is pressed.

Scan code is the number identifying one of the 83 keys to trap. See Appendix E, "Scan Codes."

KEY

Statement

Note that key trapping assumes that the left and right Shift keys are the same, so you can use a value of

&H,01, &H,02, or &H,03 (the sum of hex ,01 and hex ,02) to denote a Shift key.

You can also add multiple shift states. For example, the Ctrl and Alt keys can be added together. Shift state values must be in hex.

When trapping a key or key combinations, you must know the state of Num Lock and Caps Lock.

When you trap keys, they are processed in the following order:

1. Ctrl-PrtSc, which activates the line printer, is processed first. Even if Ctrl-PrtSc is defined as a trappable key, this does not prevent characters from being echoed to the line printer.

2. Next, the function keys Fl to Fl,0, Cursor Up, Cursor Down, Cursor Right, and Cursor Left ( 1-14) are processed. Setting scan codes 59 to 68, 72, 75, 77, or 8,0 as key traps has no effect, because they are considered to be predefined.

3. Last, the keys you define for 15 to 2,0 are processed.

Notes:

• Trapped keys do not go into the BIOS buffer so that only BASIC will know that the keys were pressed.

KEY

Statement

The following entry, "KEY(n) Statement," explains how to enable and disable function key trapping in Advanced BASIC.

Example: This example displays the soft keys on the 25th line.

50 KEY ON

This example erases soft-key display. The soft keys are still active, but not displayed.

10 KEY OFF

This example assigns the string "FILES" +Enter to soft key 1. This is a way to assign a commonly used command to a function key.

10 KEY 1,IFILES"+CHR$(13)

This example disables function key 1 as a soft key.

10 KEY 1,1111

KEY

Statement

This example sets up a Key trap for capital P. Note that all three KEY statements - KEY, KEY(n), and ON KEY-are used with key trapping.

10 KEY 15, CHR$(&H40)+CHR$(25) 20 ON KEY(15) GOSUB 1000 30 KEY(I5) ON

This example sets up a Key trap for Ctrl-Shift A.

Notice that the hex values for Ctrl (&H.04) and Shift (&H,03) are added together to get the shift state.

10 KEY 20, CHR$(&H04+&H03)+CHR$(30) 20 ON KEY(20) GOSUB 2000

30 KEY(20) ON

KEY(n)

Statement

Purpose: Activates and deactivates trapping of the specified key in a BASIC program. See "ON KEY(n) Statement. "

Versions: Cassette Disk Advanced

*** and indicates the trapped key:

function keys Fl to Fl.0 Cursor Up

Cursor Left Cursor Right Cursor Down

keys defined by the form:

KEY n,CHR$(KBflag)+CHR$(scan code).

Keys 15-2.0 can be trapped in Advanced BASIC 2 . .0 and later releases.

KEY(n) ON must be executed to activate trapping of function key or cursor control key activity. After KEY(n) ON, if a nonzero line number is specified in the ON KEY(n) statement, then every time BASIC starts a new statement it checks to see if the

specified key was pressed. If so it performs a

KEY(n)

Documents relatifs