|
|
Chapter 4 |
Programs with Graphical User Interface
Programs without Graphical User InterfaceBasic Commands
Explanation of Syntax
About the Examples
Further ExplanationsMathematical Operators
Comparison Operators
Pointers and Address Operators
Priority of the Operator
Omikron Basic offers two basic options for writing programs:
Programs with Graphical
User Interface
The use of graphical objects such as menus, dialog boxes, and windows applied
to communicate between program and user constitutes a graphical user interface. Today,
basically all commercial programs requiring a user interface offer such a graphical
user interface. Use the EasyGem Library enclosed with Omikron Basic to program graphical
user interfaces for your programs. Theoretically, it is also possible to directly
call the corresponding MacOS toolbox functions using the MAC_OS command. However,
this is considerably more complex than using the EasyGem Library and only sensible
for special cases.
Larger projects or programs to be used by others should offer a graphical user interface
since this significantly simplifies use of the program.
Programs without
Graphical User Interface
Contrary to many other modern BASIC implementations, Omikron Basic makes it possible
to write small, compact programs without graphical user interface as well. Commands
such as INPUT and PRINT are used for input and output. Such programs are especially
well suited to quickly try out the commands discussed in the next chapter when learning
how to use Omikron Basic or to just write a small program for a specific task where
previously no standard software was available or handy at the moment.
You should always use the Omikron Basic output windows for this task (to be discussed
now) to make sure that your programs still run clean within the multitasking environment
of the MacOS.
The Omikron
Basic Output Windows
Upon request, Omikron Basic makes so-called output windows available. These windows
can be used to hold all output, which would otherwise be rerouted directly to the
screen. The management of these windows is performed automatically by Omikron Basic.
Consequently, programs that have no window management and use PRINT
and INPUT for input and output run neatly in
a multitasking environment as well. The Omikron Basic output window can be activated
with the command COMPILER
"OUTPUT_WINDOW X*Y" - the maximum values for X (width) and Y (height)
to be applied to the first window have to be in pixels. The contents of the output
windows are buffered in the application heap of the program. Therefore, depending
on size and pixel depth, memory must be sufficiently available. Where appropriate,
more memory has to be reserved for the program using the finder or COMPILER
PRE_SIZE X."
If the output windows are active, a menu bar is also added, which allows easy access
to the Apple menu at the left as well as the help and program menu at the right side.
In order to make sure that Omikron Basic receives the event messages concerning the
output windows or the menu bar, the command COMPILER
"EVENT" should be used to cause a WaitNextEvent call is compiled into
the program at the appropriate location. See also the demo program 'Mandelbrot.BAS.'
If a program is running an INPUT or INPUT$ instruction, WaitNextEvent calls are always
made to the MacOS, because key pressings are constantly observed. The same applies
to the FORM_ALERT command.
The output windows also have scroll bars so that they can be designed larger
than the physical screen. However, please consider that the window contents
must be buffered in the application heap. A window with 1280 x 960 image pixels requires
in the case of, e.g., 256 colors, 1.2 MB of storage.
The increments used to scroll the window content if clicking on the arrows on the
slider bar can be adjusted with the procedure Set_Scroll_Parameter
from the Extension Library.
Note: With the command SCREEN, additional Omikron Basic output windows can be opened.
The Menu of the Omikron Basic Output Windows
If the Omikron Basic output windows are activated, an additional menu bar is created.
A few basic functions can now be called using the menu 'File.'
Open ...
The uppermost Omikron Basic output window is loaded with a file previously created
with 'Save as ... ' If the picture to be loaded has other dimensions or another pixel
depth, it is adapted automatically to the Omikron Basic output window. The file must
be available in the 'PICT' format. Thus, it can also be modified by other programs.
Save as ...
The content of the buffer for the uppermost Omikron Basic output window is stored
in the 'PICT' format. Consequently, it is possible to load and further process the
stored image by other programs.
Page Setup ...
The layout dialog box opens. The printer settings can be adjusted in this dialog
box.
Print ...
The print dialog box opens. Further adjustments can be effected in this dialog
box. The buffer for Omikron Basic is displayed in the output window after 'OK' has
been clicked on.
Quit
The program is terminated. If only one window is left open, clicking on the closer
in the Omikron Basic output window has the same effect. First, however, a security
query is issued.
Commands
and Syntax
BASIC Commands
The Omikron Basic editor accepts a whole series of BASIC commands, which are remainders
from previous versions and, among other things, were used there for controlling the
old editor and the old interpreter. Now, these functions are either carried out by
the editor itself (e.g., LIBRARY, DEFINT, RENUM, etc.) or they have lost any practical
application purpose because of the new user interface. Others are also typical interpreter
commands, which were already always ignored by the compiler because of that. Others
in turn used specific properties of ATARI hardware or of the ATARI operating system
and are therefore unimportant for the MAC.
To keep compatibility problems with older programs to a minimum (most often it already
suffices if the said commands are simply ignored), Omikron Basic is programmed so
that the editor also understands invalid commands; however, these are skipped by
the compiler.
The insignificant commands are displayed in gray in the chapter 'The Command Set'.
These keywords cannot be used by the user for his or her purposes.
Explanation of Syntax
Information in angle brackets <...> is to be replaced by the corresponding
expression.
Information in square brackets [...] is, depending on the desired application, an
addition that could be left out.
Two square brackets [[...]] set around an expression mean that this expression, depending
on the application, can be left out or appear once or several times.
Information in braces {...|...} represents a selection, from which the user is supposed
to select one of the two options separated by the bar "|".
About the Examples
Many of the commands are accompanied by short example programs that are displayed
in a field with a light yellow background. Most of these programs can be typed in
or more easily copied from the online manual and then pasted directly into a program
window. However, in many cases some compiler control words must still be placed in
order to receive a compileable program (see the Mandelbrot.BAS program in the DEMO
folder). In the case of some programs, functions from the Extension Library are also
used. In these cases, the Library must be loaded subsequently from within the editor
using 'Merge Library ...' and integrated into the program.
The monitor results are shown below in a somewhat darker yellow color, provided it
is not a question of graphics, etc. In these cases, behavior of the program is described
in a written format.
<Num. Expression>
A numerical expression is any term supplying a numerical result. In this case, the
type is unimportant (integer, simple or double precision). The compiler performs
an automatic type conversion during translation. If, however, a command, for example,
always expects only an integer type, care should be taken always to pass only integers.
Consequently, the compiled program becomes shorter and faster.
<String Expression>
An expression of the type string.
<File Name>
A file name is a string containing a FileSpecificationRecord
and has the following construction:
2 byte VolumeReferenceNumber or 0, if unknown. 4 byte DirectoryIdentificationNumber or 0, if unknown. 1 byte length of the subsequent file name, file path, or partial path. 1-63 bytes file name, file path, or partial path. |
<Num. Variable>
Numerical variables no matter what type. In individual cases, only simple variables
and no fields are maybe permitted.
<Return Variable>
Returns the result value of a command or function. In the case of INPUT USING it
is a kind of termination condition.
<Parameters>
The values passed to a function or procedure. If using CALL, a passing as a long
integer can be effected if prefixed by "L".
<Bit Number>
Unsigned number between 0 and 31. The weight of the corresponding bit is 2^<bit
number>
<Integer Variable>
Integral variables (word=16 bit or long=32 bit); field variables are also permissible.
<Memory Address>
32 bit broad long integer number specifying a specific storage cell.
<Label>
A label or flag determines a specific location within a program. It can consist of
any characters allowed for variables. A label can be:
1. A specific line:
If line numbers are used, it is possible to reach a specific line by naming its number.
The line number can also be computed, that is, any numerical expression can be used
as a label. If, however, the expression consists of only one numerical variable,
this variable has to be set within parentheses to prevent being confused with a label.
2. A specific program label:
In every location of the program a label can be identified using "-<identifier>".
The identifier may contain all characters authorized for variable names (all alphabetic
characters, digits, "_" and the characters 128 to 255). Referring to such
a label, it is simply a question of using the identifier; the prefixed minus character
is not used. It is also possible to name the label via a string expression. It has
to contain the identifier of the label and should not be longer than 8 characters,
because the compiler uses only the first 8 characters for an identification evaluation.
(This is only valid if the label is accessed via a string expression.)
In general, it is recommended to refrain from using numerical or string expressions
for line numbers and/or labels because these have to be first evaluated during runtime
and this will slow the execution of the program.
<Drive>
Drive stands for a volume (e.g., fixed disk, CD-ROM, or floppy disk) and can have
any name followed by a colon.
<Angle>
Any angle information passed to graphics commands should always
be in 1/10 degrees. For example, 900 corresponds to 90 degrees.
<File Number>
An unsigned number between 1 and 16. The number has a fixed connection with the corresponding
file (see OPEN). All commands and functions affect the file, which has been allocated
to the file number using OPEN.
Omikron Basic offers a whole line of different variable types, which are useful for different purposes. In the interest of a speedy program, only integer variables should be used - if possible - if only integers can be considered as variable values. Because strings are especially complicated, they should be avoided if at all possible.
Variable names can be created almost anyway the user desires. One variable name can also be used several times in the same program as long as different postfixes are used (meaning different value ranges). They are managed completely independent from one another. The postfix takes care of that. The ASCII characters 48-57, 65-90, 95, 97-122, and 128-255 are permitted as variable names. However, the names cannot begin with a number, otherwise BASIC cannot keep them apart from constants.
The characters starting at 128 can be accessed in different ways:
1. With a pre-selection key. First, F1 has to be pressed, and then a normal character is entered. Because of F1, 64 is added to this ASCII code. The same can be done with F2; the only difference is that 128 are added.
2. With the depressed ALT key, it is possible to enter the ASCII code of the character directly via the keypad keys. As soon as the ALT key is released or 3 digits are entered, the desired character appears on the screen.
3. The country-specific special characters can be accessed by pressing a combination of modifier keys and normal keys.
Thus, it is possible now to write, for example,
Length = Height * SIN(ß)
A suitable font is presupposed.
See also ASCII Codes.
The variable A shall serve as an example. Omikron Basic distinguishes
every individual variable from every other one, even if they are all called
A. The postfixes for each individual variable already differentiates them.
If the variable A%L has already been used, it is still possible to use the
independent fields A%L(1) and A%L(1,2) . The difference consists here
of the dimension of the fields. However, it is better to avoid such name similarities,
otherwise, a program can become unclear very fast.
Incidentally, it is also possible to allocate a standard variable type for each first
character permitted to be used as a variable character. Each variable beginning with
this letter has then automatically a different standard variable type, unless the
postfix of another variable type is explicitly named. (See also Mode/Settings>Program.)
The following variable types are possible:
Integer (whole number)
Integer numbers are whole numbers, that is, numbers without decimal places. Their
number range is limited to the values indicated below. The advantage of integer numbers
is their fast processing and that there are no rounding-off errors.
Long Integer: | Computation Range: | -2147483648 to +2147483647 |
Memory Requirement: | 4 bytes (= 4 characters) | |
Postfix: | %L e.g., A%L, A%L(1) | |
Word Integer: | Computation Range: | -32768 to +32767 |
Memory Requirement: | 2 bytes (= 2 characters) | |
Postfix | % e.g., A%, A%(1) | |
Byte Integer: | Computation Range: | 0 to 255 |
Memory Requirement: | 1 byte (= 1 character) | |
Postfix: | %B e.g., A%B(1) | |
Flag / Boolean: | Computation Range: | "false" (0) and "true" (-1) |
Memory Requirement: | 1 bit (= an eighth of a character) | |
Postfix: | %F e.g., A%F(1) |
Note: The variable types 'Byte Integer' and 'Flag / Boolean' can only be used in fields and not as independent variables.
Float (Floating Point)
Floating point numbers are numbers with decimal places. Their number range is (almost)
unlimited since they have an exponent of 10. If the number range of the fraction
is not sufficient, each exponent is increased by one, and the fraction is shifted
one place to the right. The greater the number, the more inexact it is as well. However,
the number of digits always remains identical. For example, a floating point number
looks like this:
123.45678 times | 10 to the 2nd power |
Fraction | Exponent |
Single Float: | Computation Range: | +/-1.4x10^-45 to 3.4x10^+38 |
Precision: | 7-8 places | |
Memory Requirement: | 4 byte (= 4 characters) | |
Postfix: | ! E.G., A!, A!(1) | |
Double Float: | Computation Range: | +/-4.9x10^-324 to 1.8x10^+308 |
Precision: | 15-16 places | |
Memory Requirement: | 8 byte (= 8 characters) | |
Postfix: | # e.g., A#, A#(1) |
String (Character String)
A string is a character string, that is, a text of up to 2147483648 characters in
length. The text can contain any characters from 0 to 255. Strings are managed very
effectively by Omikron Basic, which results in a very high processing speed when
comparing to other BASIC variants. The length of a string can change during the running
of the program (dynamic string management). Thus, strings do not have to be dimensioned
in Omikron Basic as they have to in many other BASIC dialects and programming languages.
Strings should only be used if the problem cannot be solved equally well using integers
because in spite of the highly optimized management of strings, their use is never
as fast as the work with integers.
For example, if only one letter is needed, it is more practical to allocate the corresponding
ASCII value to a integer variable (see ASC) and then to work with it instead of using
the letter, especially when working with loops with a high execution rate.
String: | Memory Requirement: | 16 bytes (= 16 characters) plus the length of the string. |
Postfix: | A$ e.g., A$(1) |
Constants
Constants are numbers, which do not change, that is, they are not variables.
But they too have a type, which corresponds to the variable types and is dependent
on spelling and the value of the constants:
123 | Short Integer |
35000 | Long Integer |
123. | Double Float |
1.3 | Double Float |
1E20 | Single Float |
123! | Single Float |
123# | Double Float |
1D20 | Double Float |
1.23456789 | Double Float |
"hello" | String |
Operators
Omikron Basic offers a great number of operators, which are discussed in the
following according to the organization of their function groups.
Character: | Meaning: |
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
^ | Raise to a power |
+= | Addition with allocation |
-= | Subtraction with allocation |
*= | Multiplication by allocation |
/= | Division with allocation |
\ | Integer division: Provides the result of a division rounded off to the nearest whole number |
MOD | Modul operator: Provides the rest of a whole number division |
Omikron Basic offers the following comparison operators:
Character: > |
Meaning: larger as |
< | smaller as |
= | equal |
>= | larger or equal |
<= | lesser or equal |
<> | unequal |
Pointers and Address Operators
"&" determines the address of a variable, field or function.
"*" accesses
an object (de-references it). The pointer variable must follow the operator. The
type definition also still has to be indicated here with a postfix - just as in the
case of a normal variable. In the special case of a pointer aiming towards functions,
using "*" calls the function at which the pointer variable is aiming.
Priority
of the Operators
All operators listet
here are explained in detail in Chapter 5 and listed according to priority
of the operators. The operators shown more at the top have a higher priority than
the ones at the bottom. Operators in the same line have equal priority.
( , ) (parentheses) (highest priority)
& (address operator), * (pointer operator), FN (function)
NOT, +, - (sign)
^ (raise to a power)
SHL, SHR
*, /
\, MOD
+, -
<, <=, >, >=, <>
AND
OR
EQV, IMP, NAND, NOR, XOR (lowest priority)
Example: | PRINT -3^2, (-3)^2, 3*1 SHL 2, (3*1) SHL 2 |
Result: | -9 9 12 12 |
Example: | PRINT -1>=2 OR 1<2, -1>=((2 OR 1)<2) |
Result: | -1 0 |
|
Support | Order | Start | Home: http://www.berkhan.com |
© 1997-2001 ![]() |