Omikron BASIC for Apple Power Mac

5-4. DEFDBL - FIX Contents | 5-6. INPUT$- LPRINT


Chapter 5-5

The Command Set



Type: Function
Syntax: FN <variable>[(<expression>[[,<expression>]])]
FN <functional variable>[(<parameter>[[,parameter]])]
Explanation: Calls a function defined with DEF FN and allocates the functional value to the functional variable. The parameters mentioned in the definition must be passed set in parentheses and separated with commas.
Example: PRINT FN Three_Ttimes(3)
PRINT FN Prime_Number$(12)

DEF FN Three-Times(A)=3*A
DEF FN Prime_Number$(A)
 LOCAL N,P$="Prime number"
  IF A MOD N=0 THEN P$="Not a prime number"
Result: 9
Not a prime number
See also:  DEF FN   END_FN   RETURN

Type: Command
Syntax: FOR <num.variable>= <num.expression>TO <num.expression>[STEP] <num.expression><commands>NEXT [<num.variable>]
FOR <loop variable>= <start>TO <end>[STEP <step increment>] <loop content>NEXT [<loop variable>]
Explanation: This is probably the best-known program loop. Initially, the start value is allocated to the loop variable. Each time the iterative loop is executed, the start value is increased or decreased by the step increment. If the step increment is omitted, the value will be set to "+1" automatically.
All simple variable types are candidates for loop variables, however, none of the field elements are. If the loop variable is decremented, a negative increment is to be specified (e.g., "-1").
If the loop condition is not true right at the start (e.g., initial value is larger than end value with positive increment), the loop will not be executed at all. Therefore, the FOR ... NEXT loop is a rejecting iteration.
The loop is closed with the NEXT statement whereby the loop variable can be omitted. The NEXT statement then always refers to the last FOR statement.
It is also possible to exit the loop prematurely using EXIT.
Example: FOR X#=-PI TO PI STEP .1#

DIM A(10)
FOR I=0 TO 10
 A(I)=RND(20):PRINT A(I)
FOR I=0 TO 10
PRINT "The greatest number is: ";Maximum
Result: Numbers between -PI and PI are generated first with intervals of 0.1.
The second loop writes 11 random numbers between 0 and 20 on the screen.
Finally, the third loop generates the greatest of these random numbers:
The greatest number is: . . .
See also:  NEXT   WHILE   REPEAT 

Type: Command
Syntax: FORM_ALERT (<num.expression>,<string expression>[,<variable>)
FORM_ALERT (<default>,<alert message>[,<return>)
Explanation: Displays an alert box. <Default> specifies which of the buttons mentioned in <alert message> can be triggered by the return key. If this should apply to none, <default> equal 0 is to be passed. The alert message is constructed as follows:

[Icon][Line 1| Line 2| Line 3| Line 4| Line 5|][Button 1| Button 2| Button 3]

Icon represents a number between 0 and 3:

0: No icon
1: Caution symbol
2: Note symbol
3: Stop symbol

Other values can lead to disturbances in the layout of the alert box or even cause a crash. Lines may not exceed 39 characters. The button size is based on the length of the respective text (if needed, insert blank spaces in order to generate a wider button).
After the command has been executed, <return> contains the number of the selected button.

Caution: If the mouse is deactivated, it must always be activated prior to the call, otherwise it will be impossible to operate the buttons of the alert box.
Example: File$="Trash"
FORM_ALERT (1,"[2][The File|"+File$+"|will be irrevocably deleted.][OK|Cancel]",File_Ex)
IF File_Ex=1 THEN KILL FN Get_Fsspec$(0,0,A$)
Result: If the query in the alert box is confirmed, the file called 'Trash' will be deleted from the current folder.

Type: Function
Syntax: FRAC(<num.expression>)
Explanation: Returns the fractional part of the numerical expression. The operational sign remains intact. FIX is the counterpart to FRAC.
Example: PRINT FRAC( PI ),FRAC(5.36),FRAC(-5.36)
Result: 0.141592653589793 .36 -.36
See also: FIX   INT 

Type: Command
Syntax: FRE <num.expression>
FRE <memory address>
Explanation: Releases a memory area allocated by MEMORY. The address returned when calling MEMORY is to be specified as the memory address.
Example: Buffer=MEMORY(1024)
PRINT "Buffer set up at: ";HEX$(Buffer)
FRE Buffer
Result: A buffer is created and the process documented on the screen. Subsequently, the buffer is released again with FRE.
See also: FRE as function   MEMORY   CLEAR 

Type: Function
Syntax: FRE({<num.expression>|<string expression>})
Explanation: If a numerical dummy is specified, the function returns the amount of BASIC memory available to the user, after the string heap was swept clean up (garbage collection). The value of the dummy is irrelevant.
If an empty string (="") has been passed, the function returns the amount of BASIC memory available to the user, without a prior garbage collection process being executed. The string expression would otherwise be interpreted as a volume identifier and the available memory on that volume would be determined.
Example: PRINT FRE(0), FRE(""), FRE("MacintoshHD:")
Result: Three numbers are issued, each containing the available memory in bytes.
See also: FRE as command   MEMORY   CLEAR


Explanation: Has no application purpose in Omikron Basic Mac and is ignored by the compiler. Please, do not use

Type: Command
Syntax: GET <num.expression>,{<num.expression>[,<num.expression]|<string variable>,<num.expression>}
1: GET <file number>,<record number>
2: GET < file number >,<memory address>,<number of characters>
3: GET < file number >,<string variable>,<number of characters>
Explanation: A data record is read from the file indicated by the file number and allocated to the buffer variables mentioned in FIELD according to syntax 1. The file must have been opened first using OPEN "R". If the data record is not available, the buffer variables contain blank spaces. This can be checked at any time with the function EOF, which, in this case, returns the value "-1" (=true).
According to syntax 2 and 3, the specified number of characters is read from the file indicated by the file number and posted, starting at the memory address and in the string variable, respectively. OPEN "U" should be used to open the file first.
Reading takes place starting at the current file position, which can be set with SEEK. GET may also be used to load data from the modem interface and/or the printer interface. In this case, the channel must have been opened first using OPEN "P" or OPEN "V".
See also:  PUT   FIELD   OPEN 

Type: Command
Syntax: GOSUB <label>
Explanation: Branches out into the subprogram defined by <label>. It is possible to jump back to the main program from a subprogram using RETURN. The next command following the GOSUB statement is then executed.
The variables used in the subprogram are global (see LOCAL). Programs written in Omikron Basic can basically forego GOSUB completely, since a subprogram call can always also be realized by means of a procedure. Calling a subprogram using GOSUB is actually no longer in keeping with the times. However, the command was left as part of the language volume for reasons of compatibility.
See also:  RETURN   GOTO   DEF PROC 

Type: Command
Syntax: GOTO <label>
Explanation: Branches off at the location in the program defined by <label>. The use of GOTO usually results in rather unclear programs very fast. Too many GOTOs should therefore be avoided. Structured programming - such as it is supported by Omikron Basic - always also manages without GOTO. However, the possibility that in one or two cases, the use of GOTO might simply be more practical cannot be ruled out completely (e.g., in the case of non-correctable errors).

Caution: Never branch off to a structure (loop or SELECT ... CASE) or a procedure. It is only possible to use GOTO jumps within the same hierarchy level. Use EXIT in order to exit from a structure prematurely.
See also:  GOSUB  ON   DEF PROC 

Type: Command
Syntax: GRAF_PORT <num.expression>
GRAF_PORT {<0>|<1>|<GrafPtr>}
Explanation: This command enables the rerouting of all subsequent draw commands as well as PRINT and WRITE to the specified graphics port. Either 0,1 or a valid <GrafPtr> must be passed in the numerical expression. How to open a new graphics port yourself, is explained in "Inside Macintosh, Imaging with QuickDraw".
The command GRAF_PORT 1 first checks whether a page was already opened on the printer. If this is the case, all output is routed to this page, otherwise, a new page is opened. If more than one page is to be printed at once, using LPRINT CHR$(12); (Form Feed) effects the start of a new page.
Finally, using GRAF_PORT 0 ends the printing routine; the last page is closed and the whole document (it can consist of several pages) is output to the printer.

Caution: Invalid values behind GRAF_PORT most often lead to the immediate termination of the program or even cause a complete system crash. Even if the program was only terminated, the computer should be restarted; otherwise the results might be unpredictable.

Values 0 and 1 are predefined by Omikron Basic:

0: All output is directed to the screen or the uppermost output window.
1: All output is directed to the printer.

Note: The commands INPUT and INPUT USING always reset the GRAF_PORT back to 0.
Example: Circle 0,1,"This circle is drawn on the screen"
Circle 1,4," This circle is drawn on paper"

DEF PROC Circle(GrafPtr,F,Text$)
 PRINT Text$
 CIRCLE 200*F,220*F,100*F
Result: First, the text is displayed on the screen followed by a drawn circle. The same occurs once more on paper. Therefore, it is possible to use one and the same draw routine to effect output on different devices. In addition, the use of the scaling factor F makes it possible to take advantage of the higher printer resolution.
See also:  CMD  LPRINT

Type: Command
Syntax: HCOPY
Explanation: If the OUTPUT_WINDOW is activated, a hard copy of the buffer is generated, which appertains to the uppermost window, otherwise output of the complete screen content is routed to the printer.


Explanation: Has no application purpose in Omikron Basic Mac and is ignored by the compiler. Please, do not use

Explanation: See TEXT HEIGHT

Explanation: See ON HELP GOSUB

Type: Function
Syntax: HEX$(<num.expression>)
Explanation: Converts the numerical expression to a character string, which portrays the rounded value of the expression as a hexadecimal number.
Example: PRINT HEX$(255), HEX$(-255), HEX$(-1)
Result: $FF -$FF -$1
See also:  BIN$  OCT$   VAL 

Type: Function
Syntax: HIGH(<num.expression>)
Explanation: Determines the top 16 bits of the numerical expression converted to long integer format. The counterpart to this function is LOW.
Example: PRINT HEX$(HIGH($12346789)), HIGH(-1)
Result: $1234 -1
See also: LOW

Type: Function
Syntax: H_CHAR
Explanation: This function specifies how many characters fit on the screen - one below the other. Of course, this depends on the chosen font and character size.
See also:  H_PIXEL   W_CHAR   W_PIXEL 

Type: Function
Syntax: H_PIXEL
Explanation: This function produces the height of the screen in pixels.
See also:  H_CHAR   W_CHAR   W_PIXEL 

IF ... THEN ... ELSE ... ENDIF
Type: Command
Syntax: IF <num.expression>THEN <command>[ELSE <command>] [ENDIF]
IF <log.expression>THEN <dependent commands (true) [ELSE < dependent commands (false)>] [ENDIF]
Explanation: The IF...THEN statement makes the conditional execution of commands possible. The commands that are dependent on the THEN statement are only executed if the logical expression is true (not equal to 0). The commands dependent on the ELSE statement are executed with the corresponding false logical expression (equal 0). If all dependent commands fit in one line, ENDIF can be omitted. Otherwise, ENDIF determines the block of the dependent statements. If many alternatives are available, the use of SELECT... CASE is in many instances often more advantageous.
Examples: single-line:
IF <condition> THEN ...IF <condition> THEN ... ELSE ...

IF <condition>THEN

multi-line nested with ELSE:
IF <condition>
 THEN ...
  IF < condition 2>
   THEN ...
   ELSE ...
 ELSE ...

Type: Operator
Syntax: <num.expression>IMP <num.expression>
Explanation: The two assertions are linked "logically-implement". The Boolean operation table leads to a false assertion in this case only if the first expression is true, the second, however, false.
Example: PRINT BIN$((%1010 IMP %1100)+%10000)
Result: %1101
See also:  OR   XOR   AND   NAND   NOR 

Type: Function
Syntax: INKEY$
Explanation: Loads input from the keyboard. If no input is available, the function returns an empty string. Otherwise, the string is 4 characters long. The modifier keys are returned in the first byte.
The individual bits, therefore, have the following meaning:

Bit 0: Command key
Bit 1: Shift key
Bit 2: Caps Lock key
Bit 3: Alternate key
Bit 4: Control key

If a normal key is pressed, the Virtual Key Code is entered in the second byte. See "Inside MacIntosh, Toolbox Essentials". Since on Apple computers two keys can be pressed simultaneously, the third byte contains the value of the second key, whereby two keys pressed simultaneously always have the lower value posted in the second byte and the higher in the third byte. The fourth byte contains the character code as defined by the 'KCHR' resource in the system folder.
Example: REPEAT
  A$= INKEY$ 
 FOR N=1 TO 4
  PRINT ASC( MID$(A$,N,1)),
UNTIL ASC( MID$(A$,2,1))=53 'End with ESC 
Result: No activity is taking place until the user pushes a key. The ASCII values of the four characters as well as the character appertaining to the pressed key are output to screen. The program is canceled as soon as the [Esc] key is pressed.
See also: INPUT   INPUT$ 

Type: Command
Syntax: INLINE <string expression>
Explanation: This command executes machine language commands. The machine program must be stored in the <string expression> as a hex code.
Only those registers declared 'volatile' by Apple may be modified. These are in detail as follows:
R0,R3-R12 FPR0-FPR13 CR0,CR1,CR5-CR7
R31 points to the dynamic stack. Errors caused by the machine program cannot be intercepted by Omikron Basic. During the test phase, it is therefore recommended to start a suitable debugger first.

Note: If <string expression> is a constant, the machine program can already be decoded by the compiler and inserted into the program code. As a result, a considerably faster execution is possible than in the case of a string variable or even a string expression.
See also:  CALL   USR 

Type: Command
Syntax: INPUT [[<string expression>;]]<variable>[[,<variable>]] 
INPUT [[<prompt>;]]<variable>[[,<variable>]] 
Explanation: The INPUT command loads one or several variables from the keyboard. If specified, an input prompt is issued - otherwise just a question mark. The prompt may also consist of individual strings and string expressions, each separated by a semicolon. The input is concluded with [Return]. If several values are to be input in one line, these must be separated by commas. If numerical variables are to be entered, everything up to the first invalid numeral is accepted as a value, the rest is ignored. Leading blanks are skipped in the case of numerical variables. If the first character consists of quotation marks, only the characters up to the nearest quotation mark are copied. The quotation marks themselves are omitted.
A default value can be indicated using the procedure 'Fill_Input_Buffer' from the Extension Library. This default is first displayed on the screen and can then be modified by the user or confirmed with the [Return] key.
The INPUT USING command offers considerably expanded possibilities.

Note: INPUT does not block the system. Such pseudo multitasking commands as e.g., ON TIMER GOSUB as well as other programs will continue to run. It is also possible to cancel input using [Ctrl]+[C].
Example: INPUT "Enter 3 values: ";A,B,C
INPUT @(10,0);"Enter your name: ";N$
Result: The user input will be displayed on the screen.

Type: Command
Syntax: INPUT #<num.expression>,<variable>[[,<variable>]]
INPUT #<file number>,<variable>[[,<variable>]]
Explanation: One or several variables are loaded from a sequential file. Several variables in one line can be separated by commas just as in the case of INPUT.

Note: Despite the fact, that you can read more than one element with subsequent INPUT # commands, it is recommended for the reason of clearness, to use exactly just as many variables, as elements are stored in one line of the file. If you don't know the number of items in one line, you can first read the entire line using the statement LINE INPUT # and then assign the various values to the individual variables.

Caution: INPUT # is not suitable to load data from the modem interface and/or the printer interface. The use of INPUT$ , or even better GET, is recommended.
Example: OPEN "O",1,FN Get_Fsspec$(0,0,"TEST.DAT")
WRITE #1,1,2,3
WRITE #1,4,5,6

OPEN "I",1,FN Get_Fsspec$(0,0,"TEST.DAT")
Result: 1 2 3 4 5 6
See also:  LINE INPUT #   INPUT$   GET

Type: Command
Syntax: INPUT [<string expression>;]<string variable> USING <string expression>,[<num.variable>],[<num.expression>], [<num.expression>] [,<num.variable>]
INPUT [<prompt>;]<input variable> USING <control string>,[<return variable>],[<length>], [<fill character>] [,<position variable>]
Explanation: INPUT USING enables a formatted mask input with various options for a variety of preferences. Only specific characters are permitted during input depending on the control string:

"0" digits
"à" letters (including country-specific characters)
"%" special characters (excluding country-specific characters)
"^" Ctrl character (input with [Ctrl]+[A],[Ctrl]+[letter])
"+<character>" permit individual character
"-<character>" do not permit individual character

The control characters themselves can be written in capital or small letters. To enter names, the control string could be as follows: "A +- +." (All letters including special characters, the hyphen, and the period are permitted). It would be possible to indicate telephone numbers with "0 +/".
Furthermore, the possibility exists to have specific characters converted immediately during input:

"u" convert everything to capital case letters
"l" convert everything to lower case letters
"c<character1><character2>" - if < character 1> is input it will be replaced by <character 2>" automatically.

Note: Of course, <character1> has to be listed in the selection of authorized characters.

The use of the control string "0 +.+, c.," is required to be able to always work immediately with commas instead of decimal points when entering numbers. In addition, the input is concluded with [Return]. However, additional keys or events with which to conclude input can be determined:

"x<character>" as soon as this key is pressed together with the same ASCII code as <character>, input is cancelled.

"s<character>" input is cancelled as soon as the key with the same VirtualKeyCode as the ASCII code of <character> is pressed,. This makes it possible to distinguish between e.g., numeric keypad and main keyboard as well as permitting cancellations using keys, which return a zero as their ASCII code such as [Cursor up].

"<" left margin is exceeded. Input is cancelled if the cursor is moved past the left margin.

">" right margin is exceeded. Input is cancelled if the cursor is moved past the right margin.

The <prompt> is displayed prior to input, as it is the case with all input commands, and can also contain a position datum with "@."

The <input variable> must always be a string type since this variable serves as a buffer during input. Numerical input is converted after input by means of VAL.
The <return-variable> offers information about the cause of the cancellation:

0 input was cancelled with [Return]
-1 left margin was exceeded
-2 right margin was exceeded

Positive values represent a different cancel key. This key is characterized by a value four bytes long, which - similar to INKEY$ - contains the (C)ommand bits, the (V)irtualKeyCode, and the (A)SCII code: $CC VV 00 AA (represented as hexadecimal).

Input can be limited to a specific number of characters by using <length>. The length should always be specified since an edit line exceeding a certain length (more columns than displayable) does not function correctly any longer.

The ASCII code of the <fill character> determines the character with which the edit line is deposited, indicating the input field. If nothing is specified, the "_" character is accepted as the default. Some of the conceivable applications would be e.g., 42 ("*") for the input of numbers for checks or 32 (blank) if an input mask is supposed to remain invisible.

And finally, the <position variable> determines the position the cursor occupies at the start of any input. This variable also returns the position the cursor last occupied. For example, it is possible to move the cursor directly to the error location in case input might have to be repeated. It would also be conceivable to set the cursor repeatedly to the start of input to be able to effect corrections faster.

Important: In contrast to INPUT, the <input variable> is not always first deleted but appears as default in the edit line. This enables the programmer to suggest useful input options to the user already, e.g., the current date. A simple [Return] then suffices to accept the default input. If the same or similar input is in demand repeatedly, the old value can simply remain or be modified insignificantly.

At the conclusion of input with INPUT USING, no line feed is issued. Thus, if the next output is supposed to start in a new line, a line feed has to be triggered first using PRINT.

Note: INPUT USING does not block the system. Such pseudo multitasking commands as e.g., ON TIMER GOSUB as well as other programs will continue to run. It is also possible to cancel the program using [Ctrl]+[C].
Example: Input

 PRINT @(5,5);"Name:";
 PRINT @(6,5);"Street:";
 PRINT @(8,5);"Zip/City:";
 PRINT @(10,5);"Telephone:";
 PRINT @(13,5);"Input Acceptable(Y/N)?";
 Exit$="s"+ CHR$($48)+"s"+ CHR$($50)
  SELECT Entry
   CASE 0: INPUT @(5,15);Name$ USING "a+-+ "+Exit$, K,50
   CASE 1: INPUT @(6,15);Street$ USING "a0+ +-"+Exit$, K,30
   CASE 2: INPUT @(8,15);Zip$ USING "0x "+Exit$, K,4
   CASE 3: INPUT @(8,20);City$ USING "a0+ +-+/"+Exit$, K,50
   CASE 4: INPUT @(10,15);Tel$ USING "0c-/+/+ "+Exit$, K,15
   CASE 5: Jn$="": INPUT @(13,32);Jn$ USING "u+J+N"+Exit$,K,1
  Scan= HIGH(K) AND $FF
  IF Scan=$48 THEN Entry= MAX(Entry-1,0):' Cursor up
  IF Scan=$50 OR K=0 THEN Entry=MIN(Entry+1,Max_Entry):' Cursor down
 UNTIL Jn$="J"
Result: The program enables the input of a complete address.
See also:  INPUT   INPUT$   INKEY$    USING 

5-4. DEFDBL - FIX Contents | 5-6. INPUT$- LPRINT

Tech-Support | Order | Start | Home:

© 1997-2001 Berkhan-Software