Category : BASIC Source Code
Archive   : WBB12.ZIP
Filename : BB.DOC

 
Output of file : BB.DOC contained in archive : WBB12.ZIP







BasicBasic is copyright (c) 1992 by Mark Davidsaver. All
rights reserved.


ORDER INFORMATION
-------------------------------------------------------

If you find BasicBasic useful registration is requested.
Through December 31, 1992, you will automatically receive
TWO updates for your registration fee. The registration
fee is $30.00. Please state the version of the software
that you currently have(if you have the most recent
version we begin your upgrades with the next release) and
whether 3 1/2 high density, 3 1/2 low density or 5 1/4
high density diskettes are needed. Illinois residents add
6.25% sales tax. Foreign orders in US funds only.
Foreign orders add $5.00 for extra postage.

Send check or money order to: Mark Davidsaver
213 S. Park Street
Bishop Hill, Il 61419

or phone with MC/Visa orders to: (309) 927-3303





































BasicBasic is copyright (c) 1992 by Mark Davidsaver







TABLE OF CONTENTS


Summary ................................ 2

Getting Started Quickly ................ 3

BasicBasic Basics ...................... 5

Windows Metacommands ................... 7

Metacommands ........................... 8

Statement and Function Reference ....... 9

Graphics Programming for Beginners .... 31

Programming Buttons ................... 36

Programming Menus ..................... 38

Communications Programming ............ 40

Windows and Graphics .................. 41

Windows and Fonts ..................... 44

Chaining and Common ................... 48

Default Windows Font................... 49
(386 Enhanced Mode Font information)

Errors ................................ 51

Keyboard codes ........................ 53

















1





BasicBasic is copyright (c) 1992 by Mark Davidsaver






SUMMARY
-------------------------------------------------------

BasicBasic is an easy to program, Basic-like language for
DOS or Windows. BasicBasic creates EXE files which can be
run under DOS or Windows. BasicBasic supports both
graphics and text screens. BasicBasic contains a subset
of Microsoft Basic as well as many new commands unique to
BasicBasic.

BasicBasic is an easy way to develop small to medium size
programs without regard for which environment they will
run under. BasicBasic supports mouse and buttons in both
DOS and Windows and Menus in Windows. Several commands
from more advanced Basics are also included (such as the
DIR$ function and binary file I/O from Microsoft
Professional Basic).

Programs written for BasicBasic can run under either DOS
or Windows. The compiler, itself, may run under either
DOS or Windows.

In addition to BasicBasic you will need a source editor
for the environment you are running under. BasicBasic
accepts source from standard ASCII files.

Here is a list of statements and functions the BasicBasic
compiler recognizes. Refer to the detailed description
later on for the exact syntax recognized.

ABS ADDSUBMENU ASC ATN BEEP CBUTTON CHAIN
CHR$ CIRCLE CLOSE CLS COLOR COMMON COMSTATI
COS CREATEFONT CSRLIN DATA DATE$ DBUTTON DIM
DIR$ DLEN EOF FIELD FIX FONT FONT$ FOR..NEXT
FREEMEM GET GET # GOSUB..RETURN GOTO
IF..THEN..ELSE INKEY$ INPUT INPUT # INPUT$ INSTR
INT KILL LEFT$ LEN LET LINE LINE INPUT # LOC
LOCATE LSET MAINMENU MENUITEMGRAY MENUITEMON
MID$ MKDIR MOUSEB MOUSEON MOUSEX MOUSEY ONPAINT
OPEN OPEN "COMn:" PAINT PALETTE POINT POS
POSITION POINT PRINT # LPRINT PRINT USING PUT
PUT # LPRINT USING PRESET PSET OSTYPE RADIOON
RADIOOFF RANDOMIZE READ REM RESTORE RETURN
RIGHT$ RMDIR RND SCREEN SCROLLAREA SELECTFONT
SETERRLEVEL SIN SPACE$ STOP STR$ STRING$
SYSTEM TAB TAN TIME$ TIMER UCASE$ VAL WRITE #

and the operators + - / * \ ^ AND OR





2





BasicBasic is copyright (c) 1992 by Mark Davidsaver






GETTING STARTED QUICKLY
-------------------------------------------------------

The easiest way to run BasicBasic is to have all required
files in one directory. If you are not going to be
running or compiling under either DOS or Windows you do
not need the files specific to them. BasicBasic files
required for each operating environment are:

FILE USE
_____ __________________________________

BB.EXE \_ required to compile under DOS
BB12.STB /

BBLIB12.EXE _ runtime required to run application
under DOS


WBB.EXE \_ required to compile under Windows
BB12.STB /

WBBLIB12.EXE _ runtime required to run application
under Windows
WBB.FON - Fonts required to support graphics
screens under Windows.

You may also want the provided sample programs.
(SAMPLE1.BAS, SAMPLE2.BAS, etc.)

Before compiling a program you must have the Source in an
ASCII file. Most word processors have an option to allow
reading/writing of ASCII files. Windows Write, for
example, allows you to save in Text Only format which is
ASCII. When opening ASCII files you must be sure to tell
Write to NOT convert file to Write format.

Several sample programs are provided to let you get
started quickly. The sample programs have file names of
the format SAMPLEnn.BAS.

SAMPLE1.BAS
SAMPLE2.BAS\__ Basic examples using text screens
SAMPLE3.BAS/
SAMPLE4.BAS

SAMPLEB1.BAS
SAMPLEB2.BAS __ Examples utilizing buttons
SAMPLEB3.BAS

SAMPLEG1.BAS
SAMPLEG2.BAS\__ Graphic examples
SAMPLEG3.BAS/
3





BasicBasic is copyright (c) 1992 by Mark Davidsaver





SAMPLEG4.BAS

SAMPLEM1.BAS -- Menu example


To compile a program under DOS type BB. When requested
enter the file name you want to compile. If no extension
is given the compiler will assume .BAS. You can also
enter the file name you want to compile as part of the
start command. e.g. BB SAMPLE1.BAS. The executable
file created will have the same name as the source file.

Under Windows you must compile using the program WBB.EXE.
You may install this in a group with the Program Manager
or run WBB seperately. When compile is completed you may
either execute the program or restart to compile another
program.

IMPORTANT! Whether you are compiling under DOS or Windows
only one EXE file will be created. This file will have
the same name as the source file with an extenstion of
.EXE. This EXE file can be executed under either DOS or
Windows as long as the appropriate runtime module is
present (BBLIB12.EXE for DOS or WBBLIB12.EXE for Windows).
If you are using graphics screens running under Windows
you will also need the file WBB.FON.

DOS programs require the presence of BBLIB12.EXE to run
and Windows programs require the presence of WBBLIB12.EXE
to run. If this runtime library file is not found an
error message will be returned (In Windows the absence of
WBBLIB12.EXE is indicated by 4 short beeps and the program
does not execute. You might also get the 4 short beeps if
you are running a program directly from the compiler and
do not have enough memory. In this case exit the compiler
and run the compiled program seperately.).

If you are running Windows 3.1 in 386 Enhanced Mode and
using text only screens see the section on Default Windows
Font for important information on using different font
sizes.













4





BasicBasic is copyright (c) 1992 by Mark Davidsaver






BasicBasic Basics
-------------------------------------------------------

BasicBasic is intended to be a subset of Microsoft Basic.
More statements and functions will be added with each
release. Depending on your religion you may or may not be
happy to see that GOTO is supported. BasicBasic's syntax
is 'almost' the same as Microsoft's Basic. Here are some
known syntax differences:

BasicBasic scans expressions from left to right the
same as Microsoft Basic, however, BasicBasic checks
all multiplies before divides and all minus signs
before addition.

BasicBasic does not support the underscore (_) line
extension character.

Most functions and statements have the same syntax as
Microsoft Basic. You should check the Statement and
Function Reference section for details on syntax.

Date types supported are integer (% suffix), long integer
(& suffix), single precision (no suffix), and string ($
suffix). Double precision numbers are not supported in
this version.

BasicBasic does not support a standard array of size 10.
Every array must be explicitly dimensioned with a DIM
statement.

CAPACITIES

General limits:

Maximum number of arrays: 100
Total open files: 10
Total string space: approx. 47000 chars.
Maximum character string size: 2048
Maximum Buttons: 40

Windows only limits:

Maximum menus: 6
Maximum Items in a menu: 10
Maximum Fonts Defined: 10



RESERVED WORDS

All names of statements and functions are reserved words
and may not be used as variable names. ERR is a special
5





BasicBasic is copyright (c) 1992 by Mark Davidsaver





case. This is a system wide variable used to return error
information to BasicBasic programs. See the command
SETERRLEVEL for more complete information.



















































6






BasicBasic is copyright (c) 1992 by Mark Davidsaver






WINDOWS METACOMMANDS
-------------------------------------------------------


BasicBasic contains several Metacommands to set Windows
environment parameters. These commands have no affect on
execution of the program. All Windows Metacommands have
the following format:

REM WINDOWS command

REM WINDOWS NAME name

The window name which the program will display can be
supplied. The default is the same as the file name of the
program.
e.g. REM WINDOWS NAME investments


REM WINDOWS size x1,y1,x2,y2

This command allows you to define a portion of the normal
DOS screen size as the area to be displayed in the Windows
window. This is useful if you have a program centered in
the standard 80x25 DOS screen, but do not use much of the
border area. Regular scrolling may not work in windows if
you define the window size as less than 80x25. X1 is the
left column, y1 is the top row, x2 is the right column,
and y2 is the bottom row. e.g.

e.g. REM WINDOWS SIZE 10,10,70,15






















7





BasicBasic is copyright (c) 1992 by Mark Davidsaver






METACOMMANDS
-------------------------------------------------------

metacommands are preceded by REM and a dollar sign.


INCLUDE:

This metacommand allows you to include source from
another file in the currently compiling file. files may
be nexted up to 10 levels deep.

e.g. REM $INCLUDE: moretext.asc








































8





BasicBasic is copyright (c) 1992 by Mark Davidsaver






STATEMENT AND FUNCTION REFERENCE
-------------------------------------------------------

Here is a brief description of available functions and
statements. More detailed information on those not unique
to BasicBasic can be found in standard Basic reference
books.



ABS(numericexpression)

This function returns the absolute value of the numeric
expression.



ADDSUBMENU menunumber,stringexpression,keycode

This command is ignored in DOS. Addsubmenu adds an item
to a pull down menu with the text stringexpression.
When the user selects this menu item the keycode will be
returned at the next INKEY$ function call. See the
section 'Programming Menus' for more details



ASC(string expression)

This function returns a numerical value which is the
ASCII code for the first character of string expression.



ATN(numeric expression)

This function returns the arctangent of a numeric
expression.



BEEP

This statement sounds the ASCII bell character.



CBUTTON "name",keycode,0,"type",0,left,top,xsize,ysize,
forecolor,backcolor

This command defines and creates a button on screen.
This command is DOS and Windows compatible. In screen
mode 0 left,top,xsize,ysize are in character units. In
9





BasicBasic is copyright (c) 1992 by Mark Davidsaver





graphics screen modes these must be supplied in pixel
units. The name is the text which will be displayed in
the button. When you define a button you must define
the keycode which will be returned when that button is
pressed by the user. Legal button types are "Radio",
"Push" or "Invisible". Left, top, xsize, ysize define
the position and size of the button(in character
position). Radio buttons may have a foreground and
background color defined. If these are left 0 then the
default colors will be used. In DOS the colors are also
used for Pushbuttons.

When the user presses the button the indicated keycode
will be returned to the INKEY$ function. If a button is
pressed while executing the INPUT command the input will
be ended, but the keycode will not be returned until a
subsequent INKEY$ function is called. Instead of using
the mouse to press the indicated button, the user can
also press the keyboard key which returns the indicated
keycode.

Any key may be defined for a button. See the section
"Keyboard codes" for a list of codes recognized by
BasicBasic. As an example the uppercase letter 'A'
would be the keycode 65. Extended keycodes are
indicated by adding 1000 to the second part of the code.
For example F1 would be 1059, or F10 would be 1068.

e.g. CBUTTON "Exit",1068,"Push",0,1,1,8,1,7,4

Creates a push button on the top line. Because
it is a Push button the color values are ignored
in windows, but used in DOS.

See RADIOON and RADIOOFF for instructions on
checking/unchecking radio buttons.

See the section "Programming Buttons" for more detail on
programming buttons.

Note that while CBUTTON creates a button it will not
respond to the mouse button until the function MOUSEON
has been issued.



CHAIN filespec

This command transfers control from the current program
to another program. COMMON may be used to pass
variables between programs. Files are left open when
transfering to another program. See the section
'Chaining and Common' for more details.

10





BasicBasic is copyright (c) 1992 by Mark Davidsaver





e.g. CHAIN "TEST2.EXE"



CHR$(numeric expression)

This function returns the ASCII code for the numeric
expression. The returned code is one character.



CIRCLE [STEP](x1,y),radius,[color],[start],[end],[aspect]

This statement draws a circle, ellipse, or pie section
on the graphics screen. (x,y) are the screen
coordinates of the center of the figure. Radius is the
radius in pixels. Start and End are angles in radians.
Omiting these results in a complete circle or ellipse.
You may use Start,End to draw arcs or pie sections. A
complete circle has a start randian of 0 and an end
radian of 6.2832.

If start or end are negative the value is converted to a
positive number for purposes of drawing the arc, but
then a line is drawn from the center of the figure to
the end point of the arc. PIE figures may be draw in
this way.

Example of a complete circle, radius 50, color blue

SCREEN 8
CIRCLE (100,100),50,1

Example of pie figure, filled in

SCREEN 8
CIRCLE (100,100),50,1,-.01,-2
PAINT (102,98),1,1

Aspect can be used to adjust the ratio of y radius to
the x radius. By default BasicBasic sets aspect to a
number to create round circles for the type of screen
being used.



CLOSE #filenumber

This statement terminates I/O to the indicated
filenumber. Only one number allowed for each CLOSE
command.



11





BasicBasic is copyright (c) 1992 by Mark Davidsaver





CLS

This statement clears the screen. If a scrollable area
has been define the entire screen is still cleared.



COLOR foreground,background

The format of this statement varies depending on the
screen mode you are in.

MODE 0

This statement sets the screen colors to the indicated
foreground and background colors. Color values are:

0 - Black
1 - Blue
2 - Green
3 - Cyan
4 - Red
5 - Magenta
6 - Brown
7 - White
8 - Gray
9 - Light Blue
10 - LIght Green
11 - Light Cyan
12 - Light Red
13 - Light Magenta
14 - Yellow
15 - High intensity white

Foreground values can be 0 through 15 and background
values can be 0 through 15.

MODE 8,9

The first argument (foreground color) is a color
attribute. The second argument(background color) is a
screen color. For Windows programs see the section
WINDOWS AND GRAPHICS for additional information on the
COLOR statement.

MODE 12

Only one argument is used. The first argument
(foreground) color is a color attribute. In this mode
to change the background color for the entire screen use
the PALETTE command to change the definition of color
attribute 0.

MODE 1000
12





BasicBasic is copyright (c) 1992 by Mark Davidsaver






This mode is only supported under Windows. The first
argument (foreground) is a color attribute. The second
arguement (background) is a color attribute. In this
mode to change a palette color you must use the PALETTE
command.



COMMON variablelist

Common passes variables to a chained program.
Variablelist is a list of variables and arrays whose
contents will be preserved when Chaining to a new
program. Only 'blank' common is supported. A blockname
is not allowed. the SHARED attribute is not allowed.
Arrays are indicated by blank parenthesis. See the
section 'Chaining and Common' for more details.

e.g. COMMON A,B,A$,B$()



COMSTATI(comnum)

This function returns the status of a communications
port. 8 bits of data are returned. These are defined
as follows:

bit 7 = Data Carrier Detect
6 = Ring Indicator
5 - Data Set Ready
4 - Clear to Sent
3 - Break Detect
2 - Framing Error
1 - Parity Error
0 - Overrun Error

e.g. a=COMSTATI(1)



COS(n)

This function returns the cosine of an angle expressed
in radians.



CREATE FONT

Allows creation of fonts in Windows. See section
WINDOWS AND FONTS for a description of this command.

13





BasicBasic is copyright (c) 1992 by Mark Davidsaver







CSRLIN

This function gets the current line position of the
cursor(starting with 1). In graphics mode 1000 the
pixel line position is returned (starting with 0).



DATA

This statement is used in conjuction with the READ
statement to input numeric or string constants.



DATE$

This function returns a string of ten characters
corresponding to the current computer date.



DBUTTON keycode

This statement erases a button from the screen (using
currently define colors) and disables input from it.
The keycode should be the same as that used in the
CBUTTON command. See the section "Programming Buttons"
for more information on buttons.



DIM variable(subscripts),...

Defines arrays. There is no default array size of 10 in
BasicBasic. Every array must be defined. SHARED is not
supported.



DIR$(path,[type])
or
DIR$

This function returns file names. If no type is
specified or type is set to 0 then file names not
including system and hidden will be returned. If no
path is specified then the next name using the previous
search path will be returned. Type may be set to a
non-zero value to return the names of special classes of
files.

14





BasicBasic is copyright (c) 1992 by Mark Davidsaver





type file type
1 Read Only files
2 Hidden files
3 System files
5 Directories
6 Archive bit set



DLEN (string)

This function returns the length in pixels of a string.
It is intended for use in Windows graphics mode but also
works in DOS graphics mode.



EOF(filenumber)

This function tests for end-of-file.




FIELD #filenumber,fieldwidth AS stringvariable...

This statement allocates space for variables in
random-access file buffer. The filenumber is the number
under which the file was opened. Fieldwidth is a number
indicating the length of the field and string variable
is the name of the field. Multiple fields can be
defined at once.

e.g. OPEN "TEST.DAT" FOR RANDOM AS #1
FIELD #1,18 AS NAME$,18 AS ADDRESS$
LSET NAME$="FRED SMITH"
LSET ADDRESS$="1 MAIN STREET"
PUT #1,1
CLOSE #1



FIX(numeric expression)

This function returns the integer representation of the
value in numeric expression. -n.x returns n-1 if x>0.



FONT(n)

This function returns information about a Windows font.
See the section WINDOWS AND FONTS for a complete
description of this function

15





BasicBasic is copyright (c) 1992 by Mark Davidsaver







FONT$(n)

This function returns information about a Windows font.
See the section WINDOWS AND FONTS for a complete
description of this function.



FOR..NEXT

FOR counter=start TO end [STEP increment]

Defines a program loop.



FREEMEM

This function returns the amount of global memory
available to other programs.


GET (x1,y1)-(x2,y2),arrayname

This statement gets a range of pixels from the graphics
screen and puts them into an array. The may be placed
back on the screen using the PUT statement. In
BasicBasic only one set of pixels may be stored in each
array and storing begins with the first element of the

array.

e.g.
DIM A%(100)

GET (100,100)-(109,109),A%

It is important that you dimension the array large
enough to hold the pixel data.

You can calculate the space required as follows:

size=int(((totalpixels*bits/pixel)+1)/8)+100

Where size is in bytes. Each element of an integer
array takes up 2 bytes.



GET #filenumber,recordnumber,variable$

This statement allows input of data from BINARY files.
Recordnumber is an absolute byte position in the file.
16





BasicBasic is copyright (c) 1992 by Mark Davidsaver





The first byte of the file is number 1.



GOSUB label

This statement causes a branch to a subroutine.


GOTO label

This statement causes a jump to another program
location.



IF...THEN...ELSE

Permits conditional execution depending on evaluation of
expression.



INKEY$

This function returns a character from the keyboard.



INPUT[;]["promptstring"{;|,}] variablelist

Executing this statement causes the program to pause and
wait for input. A promptstring may optionally be
printed before pausing for input. If a comma is used
after the promptstring or if no prompt string is
specified a question mark is displayed before waiting
for input. If INPUT is followed by a semicolon, then no
carriage return line feed is performed after the Enter
key is pressed.



INPUT #filenumber,variablelist

This statement reads items from an open file to the
given variables. When inputting data leading spaces
will be ignored.



INPUT$(n,port)

This function returns a string of n characters from a
communications port. If n characters are not available
17





BasicBasic is copyright (c) 1992 by Mark Davidsaver





the function will WAIT for that many characters to
arrive. To avoid 'hanging up' your program use the LOC
function to find how many characters are waiting. If a
communications error occurs the number of characters
returned may be less than what you requested. In this
case use the function COMSTATI to determine what error
occured. See the section "Communications Programming"
for more details.



INSTR([start],expressiontosearch,searchforexpression)

This function searches for the first occurence of
searchforexpression in expressiontosearch and returns
the position at which the match is found. If no match
is found then 0 is returned.



INT(numericexpression)

This function returns the largest integer less than or
equal to numericexpression.



KILL stringexpression

This command deletes the file whose name is in
stringexpression.



LEFT$(stringexpression,n)

This function returns a string of length n from the left
part of stringexpression



LEN(stringexpression)

This function returns the number of characters in
stringexpression.



LET

May optionally be used before assignment statements.
e.g. LET I=3


18





BasicBasic is copyright (c) 1992 by Mark Davidsaver






LINE [STEP](x1,y1)-[STEP](x2,y2),[color],[B],[BF]

This command draws a line, box, or filled box on the
graphics screen. The (x1,y1), (x2,y2) arguments are the
end points of the line. If a color is not specified the
current foreground color will be used. The 'B' option
draws a box. BF draws the box and paints the interior.



LINE INPUT #,filenumber,stringvariable

This statement inputs an entire line from a file. Input
continues until the next carriage return.



LOC(filenumber)

This function returns the current absolute byte position
within a file. For a communications port it returns the
number of received characters waiting in the receive
buffer.



LOCATE row,column,[cursor]

Positions the cursor on the screen. If cursor is set to
0 then the cursor is turned off. In graphics mode 1000
row, column are pixel positions (starting with 0) rather
than character positions (starting with 1).



LPRINT expressionlist [,|;]

Prints the items in expression list. See PRINT for a
more complete description.



LPRINT USING formatstring; expressionlist[,|;]

The formatstring tells how to print the items in
expressionlist. See PRINT USING for a description of
format string items.



LSET stringvariable=string expression

This command puts data into a random access file buffer.
19





BasicBasic is copyright (c) 1992 by Mark Davidsaver





The buffer must be previously defined by a FIELD
statement. The data is left justified in the field.

e.g. OPEN "TEST.DAT" FOR RANDOM AS #1
FIELD #1,18 AS NAME$,18 AS ADDRESS$
LSET NAME$="FRED SMITH"
LSET ADDRESS$="1 MAIN STRING"
PUT #1,4
CLOSE #1



MAINMENU stringexpression,stringexpression...

This command is ignored in DOS. This command defines
the main menu bar for Windows. Up to six sub menu names
may be specified. If less than six are defined, blank
strings must be present. See the section 'Programming
menus' for more detail.

e.g. MAINMENU "File","Color","Options","","",""



MENUITEMGRAY keycode

This command is ignored in DOS. This command 'grays' a
submenu item. While gray the item cannot be selected by
the user. See the section 'Programming menus' for more
detail.



MENUITEMON keycode

This command is ignored in DOS. This command enables a
submenu item. When enable a user may select this menu
item.



MID$(stringexpression,n,length)

This function returns a string composed of length
characters starting with character n in
stringexpression.



MKDIR stringexpression

This command creates a directory specified by
stringexpression

20





BasicBasic is copyright (c) 1992 by Mark Davidsaver







MOUSEB

This function returns information on whether mouse
buttons are pressed. Bit 0 is 1 if left button is
pressed. Bit 1 is 1 if right button is pressed. Bit 2
is 1 if middle button is pressed.

e.g. b=mouseb
b=b and 2
if b<>0 then
print "right button is pressed."
end if



MOUSEON

This function intializes the mouse. It returns a -1
(true) if a mouse is present. It returns 0 if no mouse
is present. This function must be issued before the
mouse can be used in both DOS and Windows.

e.g. mouseflag=mouseon



MOUSEX

This function returns the x position of the mouse in
character units (1 through 80) for screen mode 0 and in
pixel units (0 through top) in all other screen modes.

e.g. x=mousex



MOUSEY

This function returns the y position of the mouse in
character units (1 through 25) for screen mode 0 and in
pixel units (0 through top) in all other screen modes..

e.g. y=mousey



ON PAINT line number

This statement defines a subroutine which handles screen
updates. This statement is ignored in DOS. This
statement is optional in Windows. See the section on
Windows and Graphics for more detail.
21





BasicBasic is copyright (c) 1992 by Mark Davidsaver








OPEN filename FOR mode [ACCESS access] AS # [LEN=reclen]

This command prepares the file filename for access as
number #. The filename can be a file name with or
without a pathname. Modes supported are INPUT, OUTPUT,
APPEND, BINARY, RANDOM. INPUT, OUTPUT, APPEND are for
sequential files. RANDOM is for random-access files
with fixed length records. BINARY can be used to access
any byte of any file.

Access types supported are READ, WRITE, or READ WRITE.
This argument is optional and is only valid for BINARY
and RANDOM files. READ WRITE is the default. If you
specify READ you will get an error if you try to access
a file marked as read-only by DOS.

LEN is used for random access files. It is the record
length. This argument is optional. 128 is the default.

e.g. OPEN "TEST.DAT" FOR INPUT AS #1

e.g. OPEN "TEST.DAT" FOR RANDOM ACCESS READ AS #1

e.g. OPEN "TEST.DAT" FOR RANDOM ACCESS READ WRITE AS #1

e.g. OPEN "T.DAT" FOR RANDOM AS #1 LEN=128



OPEN "COMn: speed,parity,data,stop" FOR RANDOM AS #n LEN=n

This statement opens and initializes a communications
port. COM1 and COM2 are supported. Supported speeds
are 9600, 4800,2400,1200,and 300. Parity may be either
E,O,N, or M. Data may be either 5,6,7, or 8. Stop may
be either 1, 1.5, or 2. LEN is used to specify the size
of the input buffer. The default is 128 bytes. For
Windows programs a minimum of 2048 is suggested.

Only PRINT # will output characters to an open
communications port. Only INPUT$ will receive
characters from a port.

Communications parameters may be omitted; however, their
position must be marked by commas. Default parameters
are 300 baud, No parity, 8 data bits, and 1 stop bit.

e.g. OPEN "COM1: 2400,E,7,1" for random as #1 len=2048

See the section "Communications Programming" for more
details.
22





BasicBasic is copyright (c) 1992 by Mark Davidsaver








OSTYPE

This function returns a number indicating what operating
system the program is running under.

1 - DOS
2 - Windows 3.x
3 - ?



PAINT [STEP](x,y),[paint],[border]

This statement fills a graphics area with the color
selected. (x,y) is the first point filled. It will be
filled with the color specified by the attribute
'paint', if supplied. If not supplied the foreground
color is used. Coloring in all directions continues
until the 'border' color is encountered. If border
color is not supplied the paint color is used.



PALETTE attribute,color

This statement allows you to change the default graphic
colors provided by BasicBasic. The usage of the
attribute and color arguments depends on the screen mode
you are in. You can always find out your current screen
mode using the SYSTEM function. For Windows programs
see the section on WINDOWS AND GRAPHICS for additional
information on the PALETTE statement. Here are the
definition of the arguments for various screen modes:
screen color.

MODE 8

Attribute determines which one of the 16 color
attributes you want to redefine. It is the attribute
you select with the COLOR statement. In this mode you
have 16 colors to choose from (0 to 15). See the
COLOR statement for a listing of the colors.

MODE 9

Attribute determines which one of the 16 color
attributes you want to redefine. In this mode you
have 64 colors to choose from (0 to 63).

MODE 12

23





BasicBasic is copyright (c) 1992 by Mark Davidsaver





In this mode attribute determines which one of the 16
color attributes you want to redefine. In this mode
the color value reflects an exact RGB definition of
the color you want. If you use a variable for color
it must be of type long integer.

color= 65536 * blue + 256 * green + red

Where blue, green, red can be from 0 to 255.



POINT (x,y)

This function returns the color of the specified
graphics pixel.



POS(0)

This function returns the current column position of the
cursor(starting with 1). In graphics mode 1000 this
function returns the pixel column (starting with 0).



POSITION x1,y2,xlen,ylen

This statement sizes and positions a window. x1,y1 are
the upper left of the window. This statement is ignored
in DOS.



PRESET [STEP](x,y),[color]

This command sets one pixel on the screen to the
specified color. By using the STEP prefix you can
specify that the x,y coordinates are relative to the
current position. If no color is supplied the pixel is
set to the background color.



PRINT expressionlist [,|;]

Prints the items in expression list. PRINT with no
expression results in a blank line being printed. If
the expression is followed by a semi-colon (;) the next
print starts immediately following this one. If the
expression ends in a comma (,) the next print starts at
the next print position. Print positions are at columns
1, 15, 29, etc.
24





BasicBasic is copyright (c) 1992 by Mark Davidsaver








PRINT USING formatstring; expressionlist[,|;]

The formatstring tells how to print the items in
expressionlist. Any text may be in formatstring.
BasicBasic only recognizes three format characters.
These are pound sign (#) comma (,) and period (.).
Each time a number character is found (#) one item from
the expression list will be printed.

e.g. PRINT USING "The answer is: ###,###.##";number



PRINT #filenumber,expressonlist

Prints to a file or communications port the items in
expression list.



PSET [STEP](x,y),[color]

This command sets one pixel on the screen to the
specified color. By using the STEP prefix you can
specify that the x,y coordinates are relative to the
current position. If no color is supplied the pixel is
set to the foreground color.



PUT (x,y),arrayname,action

This statement places pixels stored in an array onto the
screen. (x,y) is the upper left position. The x and y
length placed on the screen depends on the GET statement
which stored the data into the array.

The action may be one of the following:

XOR - Combines the pixels in the array and those
on the screen using the XOR operator.
This is the most common action used for
motion since this automatically restores
the background when done twice. XOR is
the default.

PSET - Transfers data erasing what is already on
the screen.

PRESET - Inverts data and transfers to screen
erasing what is already on the screen.
25





BasicBasic is copyright (c) 1992 by Mark Davidsaver






AND - Masks screen image with data in array.

OR - Superimposes data on existing screen.

For Windows use see the section WINDOWS AND GRAPHICS for
more information.


PUT #filenumber,recordnumber,stringexpression
PUT #filenumber,recordnumber

This statement is used to output data to a file opened
in either BINARY or RANDOM mode.

In BINARY mode the string expression will be written to
the file at the byte location given by recordnumber.
Recordnumber is the absolute byte number to be written,
where the first byte of the file is 1.

e.g. A$=SPACE$(20)
PUT #1,100,A$ (writes 20 bytes starting at 100)


In RANDOM mode the data in the output buffer will be
written to the record number indicated.

e.g. PUT #1,1 (writes to record 1)



RADIOON keycode

This command 'checks' the indicated Radio button. See
the section "Programming Buttons" for more information.



RADIOOFF keycode

This command 'unchecks' the indicated Radio button. See
the section "Programming Buttons" for more information.



RANDOMIZE

This statement initializes the random number generator.
If you use the RND function you probably want to preceed
it's use with the RANDOMIZE statement. Otherwise
everytime your program runs you will get the same
sequence of 'random' numbers. This statement has no
arguments.

26





BasicBasic is copyright (c) 1992 by Mark Davidsaver







READ variablelist

Inputs a value from a DATA statement.



REM

Denotes a comment line and is ignored by the compiler.



RESTORE label

Sets position that next READ statement will input data
from.



RETURN

Returns program execution to location immediately after
last GOSUB.



RIGHT$(stringexpression,n)

This function returns a string of length n from the
right part of stringexpression



RMDIR stringexpression

This command removes the directory given by
stringexpression.



RND

This function returns one in a sequence of random
numbers between 0 and 1.


SCREEN mode[,palette]

This statement selects the screen mode. The actual
screen mode available depends on your hardware. The
modes available in this version of BasicBasic are:

27





BasicBasic is copyright (c) 1992 by Mark Davidsaver





0 - Text Only. This is the default.

2 - 640-200 Graphics. Black and white only.
80 x 25 text format. (CGA, EGA, VGA)

8 - 640-200 Graphics. 16 colors and 16 attributes
80 x 25 text format (EGA,VGA)

9 - 640-350 Graphics. 16 colors and 16 attributes
80 x 25 text format (EGA,VGA)

12 - 640-480 Graphics. 256,000 colors and 16 attributes
80 x 30 text format (VGA)

1000 - Special Window mode. Supports whatever graphics
resolution Window supports. Supports custom
fonts. Issueing a SCREEN 1000 under DOS results
in selection of the highest available graphics
mode (2, 8, 9 or 12).

The Palette argument is ignored under DOS. Under Windows
it allows you to select the special BasicBasic palette
if set to 16, or to select the 'system palette' if set
to 0. If the Palette argument is omitted then the
default is 0, use the system palette. See the section
WINDOWS AND GRAPHICS for more detail.

Here are examples of how the SCREEN command might be
used under Windows.

SCREEN 8 -- system palette
SCREEN 8,0 -- system palette
SCREEN 8,16 -- special BasicBasic palette

If you do not know the output capabilites of the machine
your program is going to run on, use the SETERRLEVEL
command to determine if a screen mode has been
successful. Here is an example:

SETERRLEVEL 5
ERR=0
SCREEN 12
IF ERR>0 THEN
ERR=0
SCREEN 9
IF ERR>0 THEN
ERR=0
SCREEN 8
IF ERR>0 THEN
PRINT "GRAPHICS NOT AVAILABLE."
STOP
END IF
END IF
END IF
28





BasicBasic is copyright (c) 1992 by Mark Davidsaver






The SCREEN command resets SCROLLAREA to entire screen.




SCROLLAREA leftx,topy,rightx,bottomy

This statement defines an area of the screen which is
used for scrolling. This allows you to create fixed
text or buttons in one area of the screen while
scrolling another area. In screen modes less than 1000
Leftx, topy, rightx, bottomy are in character units and
are inclusive(starting with 1). In screen mode 1000
leftx, topy, rightx, bottomy are pixel units(starting
with 0).

Executing the CLS command will clear the entire screen,
not just the scrollable area. PRINT CHR$(12); will only
clear the scrollable area.



SETCOM comnum,"Speed,Parity,Databits,Stopbits,dtr,rts"

This statement allows you to change communications
parameters for an already opened communications port.
Speed, Parity, Databits, and Stopbits are described in
OPEN COM. DTR may be either ON or OFF. If ON then the
output data terminal ready signal will be set high. ON
is the default. RTS may be either 1 or 0. If 1 then
the output request to send is high. 1 is the default.
Communications parameters not present will not be
changed; however, a comma must mark their positions.

e.g. SETCOM 1,",,7"

Sets number of data bits to 7.

e.g. SETCOM 1,",,,,OFF"

Turns Data terminal read;y off.

See the section "Communications Programming" for more
information.



SETERRLEVEL level

This command defines what BasicBasic should do in case
of runtime errors. Level must be a number (not an
expression or variable). Level 7 causes execution to
halted for all errors. Level 5 causes execution to
29





BasicBasic is copyright (c) 1992 by Mark Davidsaver





continue for recoverable errors. In the latter case the
global variable ERR is set to the error number. ERR may
be reset with the statement: ERR=0. ERR will be reset
each time an error occurs so the program must check ERR
immediately after statements which may produce errors.



SIN(x)

This function returns the sine of an angle expressed in
radians.



SPACE$(N)

Returns a string of n spaces.



STOP

Causes the program to cease execution.



STR$(numericexpression)

This function returns a string representation of the
numbericexpression.



STRING$(m,stringexpression)

This function returns a string of length n. This string
is composed of the first character in stringexpression.



SYSTEM (n)

This function returns information on the screen
depending on the value of n passed to it. This
information is of most use to Windows programs.

n function returns
--- ----------------------------------
1 Maximum x allowed in a graphics program
2 Maximum y allowed in a graphics program
3 Actual maximum screen size x
4 Actual maximum screen size y
5 Maximum color attribute
30





BasicBasic is copyright (c) 1992 by Mark Davidsaver





6 Maximum 'background color' in COLOR statement
7 Current screen mode
8 Window left position
9 Window top position
10 Window x size
11 Window y size
12 Returns 1 if window is Active Window, 0
otherwise. See WINDOWS AND GRAPHICS for
more information on uses of this value.



TAB(numericexpression)

In PRINT or LPRINT statements positions output at column
position given in numericexpression.



TAN(x)

This function returns the tangent of an angle expressed
in radians.



TIME$

This function returns a string representation of the
current system time.



TIMER

This function returns the number of seconds since
midnight.



UCASE$(stringexpression)

This function converts all lower case characters in
stringexpression to upper case and returns as new
string.



VAL(stringexpression)

This function returns the numeric value of string
stringexpression.


31





BasicBasic is copyright (c) 1992 by Mark Davidsaver






WRITE #filenumber,expression list

Write is performs the same way as Print with these
exceptions: 1) Commas are inserted between all items;
2) Strings are bracketed by quotation marks.

BasicBasic does not support using the Write statement to
display on the screen.













































32





BasicBasic is copyright (c) 1992 by Mark Davidsaver





GRAPHICS PROGRAMMING FOR BEGINNERS
-------------------------------------------------------

This section will show you the basics of graphics
programming in BasicBasic. The examples given will work
equally well running under DOS or Windows.

Now here is your first graphics program:

SCREEN 2
LINE (0,0)-(400,100)
INPUT Z

This program draws one diagonal line on the screen. The
key to graphics programming is the SCREEN command. You
must issue a SCREEN command to tell BasicBasic that you
are going to do graphics. Screen 2 puts your screen into
a graphics mode with 640 dots (pixels) across and 200 dots
down. Each dot is either white or black. Most of our
examples will use SCREEN 8, which has the same number of
dots, but 16 colors. If you are running on a CGA display,
SCREEN 2 is the only graphics mode available, so you will
have to adjust these examples.

The second line in our example contains the LINE
statement. The LINE statement will do much more than make
lines. It will also create boxes and fill them with a
color if you want. Here is another program:

SCREEN 8
LINE (0,0)-(400,100),4,B
INPUT Z

This program puts the hardware into a 16 color mode and
then creates a box with red lines. The 'B' at the end of
the statement is what tells it to make a box. Notice that
the diagonal line is not drawn on the screen. Instead the
end points in the statement are used as the opposing
corners of the box. The 4 specifies the color red. You
could also do the following:

SCREEN 8
LINE (0,0)-(400,100),4,BF
INPUT Z

This program has 'BF' instead of 'B' in the LINE
statement. The 'BF' says to draw a box and then fill it
with the same color.

Of course you can also use a variable in place of the
numeric constants we have used so far:

SCREEN 8
FOR I=0 TO 15
33





BasicBasic is copyright (c) 1992 by Mark Davidsaver





X=I*10
Y=I*5
MYCOLOR=I
LINE (X,Y)-(X+10,Y+10),MYCOLOR,B
NEXT I
INPUT Z

This creates a series of boxes.

If you are tired of sharp corners try this:

SCREEN 8
CIRCLE (100,100),50,4
INPUT Z

As you might expect this draws a circle. The center of
the circle is at 100,100; it has a radius of 50 and is
drawn in red(the 4). The CIRCLE statement will do much
more than draw circles; it will also draw arcs and pie
sections. Try this:

SCREEN 8
CIRCLE (100,100),50,4,0,3.1416/2
INPUT Z

This draws a quarter circle (an arc) starting to the right
and finishing up at the top. To do this we are added 2
more arguments to the CIRCLE statement; 0 and 3.1416/2.
These are the start and end angles in radians of the arc.
There are 2pi radians in a circle. Don't remember this
from high school? Just remember that 0 is to the right;
3.1416/2 is up, 3.1416 is left, and 4.7124 is down.

Putting a minus sign before the start and end angles cause
BasicBasic to draw a pie section.

SCREEN 8
CIRCLE (100,100),50,4,-.01,-2
INPUT Z

This draws a pie section slightly greater than a quarter
circle. The CIRCLE statement does not have a fill option
like the LINE statement. If you want to fill your pie
section with a color you should use the PAINT statement.
This is a very versatile statement. You use it like this:

SCREEN 8
CIRCLE (100,100),50,4,-.01,-2
PAINT (102,98),4,4
INPUT Z

Now we have a red pie section. Paint starts filling the
screen with color starting with the center point given and
proceeding to the border color. Notice that we made our
34





BasicBasic is copyright (c) 1992 by Mark Davidsaver





center point different than 100,100 to make sure it was
inside the pie section we previously drew with the CIRCLE
command. We could have a blue pie section with red border
with the following:

SCREEN 8
CIRCLE (100,100),50,4,-.01,-2
PAINT (102,98),1,4

We will mention one last statement in this introductory
discussion. This is the PSET statement. It allows you
set individula pixels on the screen.

SCREEN 8
FOR I=1 TO 100
MYCOLOR=INT(RND*16)
X=INT(RND*640)
Y=INT(RND*200)
PSET (X,Y),MYCOLOR
NEXT I
INPUT Z

The preceeding program 'splatters' 100 randomly placed
pixels on the screen. They also have random color.

We won't discuss them here but other statements useful in
graphics programming are:

PRESET
GET
PUT
COLOR
PALETTE

Refer to the graphics programming examples SAMPLEG1.BAS,
SAMPLEG2.BAS, SAMPLEG3.BAS and SAMPLEG4.BAS for more ideas
on graphics programming.

















35





BasicBasic is copyright (c) 1992 by Mark Davidsaver






PROGRAMMING BUTTONS
-------------------------------------------------------

Buttons can be used in either DOS or Windows. Buttons do
not require the presence of a mouse. Here is an example
of a valid create button command:

CBUTTON "EXIT",1068,0,"Push",0,1,1,8,1,7,4

Here is a description of each parameter:

EXIT - This is the name displayed in the button

1068 - This is keycode for F10 (User can either
use mouse to push button or press F10.

0 - Reserved

Push - Type of button. 'Radio' is the other type.

0 - Reserved

1 - Left position

1 - Y position

8 - x size (in characters)

1 - y size (in characters)

7 - foreground color (In Windows only used for Radio
buttons).

4 - background color (In Windows only used for Radio
buttons).

In DOS a push button will have text centered and if the
defined text size is at least 2 characters smaller than
the button size a line will be drawn around the outside.

In graphics modes button position and size is given in
pixel units rather than character units.

Remember that if a mouse is going to be used it MUST be
turned on with the MOUSEON function before it can be used
to press a button.

Here is an example of a small program which uses buttons:

A=MOUSEON
IF A=-1 THEN
CBUTTON "EXIT",1068,0,"PUSH",0,70,1,8,1,0,0
ELSE
36





BasicBasic is copyright (c) 1992 by Mark Davidsaver





CBUTTON "F10-Exit",1068,0,"PUSH",0,70,1,10,1,0,0
END IF
INPUT Z
a$=INKEY$
PRINT LEN(A$)

This program displays different text in the button
depending on whether a mouse is present or not.
Assuming there is a mouse this program will end under
the following conditions:

- User presses EXIT button with mouse
- User presses F10 on keyboard
- User presses ENTER key on keyboard.

In the first two cases the print will show a length of 2
for the length of A$ since the button keycode will be
returned on the next INKEY$ after the INPUT is
terminated.

Once you have created a button you are responsible for NOT
writing anything to that area of the screen. If you do
the button will be erased. If you are using buttons and
scrolling text on the screen make sure you use the
SCROLLAREA command to protect the button area of the
screen.

INVISIBLE buttons can be particularly useful. An
invisible button does not appear on the screen, but a
button push inside it's defined area will return it's
keycode just as if it were. This allows you to create
your own special color buttons or input areas. For
instance you could have a series of INPUT statements in a
program and each could be defined as an invisible button.
When the user clicked on that input area you would get a
unique keycode which would direct your program to the
section of code which handles that input.

Since buttons end INPUT commands you can also use
invisible buttons to define any keys you want to end INPUT
commands (e.g. UP ARROW or DOWN ARROW).













37





BasicBasic is copyright (c) 1992 by Mark Davidsaver






PROGRAMMING MENUS
-------------------------------------------------------

Menus are not supported in DOS. Menu commands are ignored
when running under DOS.

Menus support in BasicBasic is much like button support.
When the user selects a menu item a defined keycode is
returned to the Basic program. Menu keycodes are returned
only using the INKEY$ function call. However, if the user
selects a menu item while the program is waiting for input
in an INPUT command the input command will be terminated
just as if the user had pressed Enter. Then on the next
INKEY$ call the keycode for the menu item will be
returned.

KEYCODES: Just as in buttons keycodes can be regular or
extend keys. Extended keys are indicated by adding 1000
to the regular keycode. F10 would be 1068. See the
Appendix 'Keyboard codes' for a complete list.

The mouse must be enable with the MOUSEON command before
any menu items will be recognized.

Here is an example of a simple Windows program which
utilizes menus.

y=mouseon
mainmenu "Color","","","","",""
addsubmenu 1,"Black",1059
addsubmenu 1,"White",1061
backcolor=0
menuitemgray 1059
50
cls
color 1,backcolor
locate 10,30
print "Sample text..";
100
a$=inkey$
if a$="" then goto 100
if len(a$)=1 then goto 100
if right$(a$,1)=chr$(59)
menuitemon 1060
menuitemgray 1059
backcolor=7
goto 50
elseif right$(a$,1)=chr$(60)
menuitemon 1059
menuitemgray 1060
backcolor=0
goto 50
end if
38





BasicBasic is copyright (c) 1992 by Mark Davidsaver





goto 100

This program defines one menu and then adds two items to
it. These menu items allow the user to clear the screen
to either black or white. The program disables the menu
item for whatever color the screen currently is.

The menu could be define in the following way also.

mainmenu "&Color","","","","",""
addsubmenu 1,"&Black",1059
addsubmenu 1,"&White",1061

The apersand (&) allows you to define which character in
the menu will be underlined which allows the user to
select this item by pressing the ALT key and this letter.
This IS NOT the keycode which will be returned to your
program. This keycode will always be the one given as the
last parameter of the addsubmenu command.

We could also define the menu like this:

mainmenu "&Color","","","","",""
addsubmenu 1,"&Black",1059
addsubmenu 1,"",0
addsubmenu 1,"&White",1061

The 3rd line (addsubmenu 1,"",0) creates a line seperator
in the menu bar. It can not be selected by the user.

























39





BasicBasic is copyright (c) 1992 by Mark Davidsaver






COMMUNICATIONS PROGRAMMING
-------------------------------------------------------

Here is a brief example of using a communications port.

rem
rem open communications port
rem
OPEN "COM1: 2400,N,8" FOR RANDOM AS #1 LEN=2048

100

rem
rem get input from communications port
rem
t = LOC(1)
IF t > 0 THEN
a$=input$(t,1)
if len(a$)>0 then
rem come here to display received characters
PRINT a$;

ELSE
rem come here if some kind of comm error that kept
rem us from getting the waiting character.

end if

END IF

rem
rem get input from keyboard
rem

b$ = INKEY$

IF b$ <> "" THEN

PRINT #1, b$;

END IF

GOTO 100










40





BasicBasic is copyright (c) 1992 by Mark Davidsaver







WINDOWS AND GRAPHICS
-------------------------------------------------------

In general programming graphics under Windows is the same
as programming graphics under DOS. However, because
Windows mediates hardware access among different programs
there are a few differences.

COLORS

Under DOS or Windows, BasicBasic provides a palette of 16
colors. Under DOS this palette is the hardware palette
and you have full control to change them (depending on
mode using either the COLOR or PALETTE statements). Under
Windows the palette is a 'logical' palette and only
Windows controls where in the physical palette the logical
palette entries are placed. In addition, if you are
running under standard VGA or less, Windows will not let
you change the colors in the palette. You are restricted
to the 16 colors Windows defines.

BasicBasic defaults to using the system palette. This is
a palette of 16 colors which Windows never changes. This
also means that your program cannot change them with the
PALETTE or COLOR(in mode 8) commands. If you want to
change the standard colors you will have to use a
'logical' palette. In BasicBasic you do this using the
SCREEN command.

Using a logical palette has benefits and drawbacks. As
mentioned you can change the colors display. This may be
of use in animation. However, there are serious
drawbacks. The PUT with any option except PSET will not
work correctly. This is explained below. Also, when your
program is not the 'active' window, Windows may remove
your colors from the hardware palette resulting in some
strange looking displays. In addition, if this happens,
the PAINT command may have completely unforseen
consequences. You can use the SYSTEM function to
determine if your program is the active program. When
your program is active your colors will all be available
for your use.

Logical palettes do not support using the PUT graphics
statement with the XOR, OR, or AND options. If you use
XOR the colors will not be as expected (though, as usual
if you do 2 PUT statements with XOR the background will be
restored). The reason for this is that Windows may 'map'
the logical palette entries to the physical palette anyway
it likes. If you must use XOR, use the default BasicBasic
palette which is the system palette.

41





BasicBasic is copyright (c) 1992 by Mark Davidsaver






SCREEN MODES

Under Windows you have access to the same screen modes as
under DOS. The COLOR and PALETTE statements work the same
under DOS as under Windows. In addition under Windows you
have access to an additional screen mode: mode 1000. In
mode 1000 you are able to create new fonts. Mode 1000
gives you the highest possible graphics resolution. Also
the COLOR command is somewhat more flexible than under DOS
screen modes. The LOCATE and SCROLLAREA statements and
functions POS, CSRLIN work differently in this mode.


NAKED WINDOWS

When running under Windows you do not have exclusive
access to the screen. At any time your window may be
hidden by another window appearing on the screen. At some
future time the operator may make your window reappear
with the click of the mouse button. When your window has
been hidden and is then called to the front, Windows DOES
NOT handle putting the contents of the window back in!
All windows privides is the outline of the window. This
'naked' window must be filled in by either BasicBasic or
your program.

By default BasicBasic handles all window 'repainting'.
BasicBasic remembers everything that your program sends to
the screen and when necessary repaints the window with
this information. In text mode (screen mode 0) a small
buffer remembers each character on the screen. In
graphics mode BasicBasic maintains a larger buffer
containing a duplicate of each pixel on the screen. This
buffer can take up quite a bit of space.(On a 640 x 200 16
color display this requires 128,000 bytes). Ordinarily
you don't need to worry about this. If your program isn't
going to be in memory very long, or has a small window,
who cares?

If you are short of memory or have a very large window
which is going to stay around all day you may not like
this arrangement. In this case you should use the ON
PAINT statement. This statement tells BasicBasic to NOT
keep a copy of the display; that you are going to handle
repainting when necessary. Here is an example:

ON PAINT GOSUB 1000
SCREEN 8
sc=8
gosub drawmyscreen
50
if inkey$="" then goto 50
STOP
42





BasicBasic is copyright (c) 1992 by Mark Davidsaver






1000
gosub drawmyscreen
RETURN

drawmyscreen:
is sc=0 then return
locate 1,1
print "Now is the time to draw circles..."
circle (50,50),25,4
circle (75,75),50,1
circle (400,50,40,2
circle (500,100,75,3
return

Here are some rules to remember about using the ON PAINT
statement:

- Use it before your SCREEN statement. BasicBasic
creates the screen duplicate during the SCREEN
statement. It will, if necessary, erase it during the
ON PAINT statement, but why go to the bother.

- NEVER use any input commands, file commands, com
commands, etc in you ON PAINT handler.

- Don't change variables in your ON PAINT handler that
are used elsewhere in your program. Remember that
Windows ALWAYS calls your ON PAINT handler at the
WORST POSSIBLE TIME!

- It is wise not to use the INPUT command in a program
that has it's own ON PAINT handler. BasicBasic will
not rewrite what has been input so far.

- Your ON PAINT handler may be called IMMEDIATELY after
you issue the ON PAINT command. Make sure you are
ready. Note the line IF SC=0 THEN RETURN in our
example. Try running this program without this line.















43





BasicBasic is copyright (c) 1992 by Mark Davidsaver







WINDOWS AND FONTS
-------------------------------------------------------

To create fonts in Windows you must have selected Screen
mode 1000. In this mode some statements and commands work
differently. LOCATE x,y now position by dot position,
rather than character position. POS and CSRLIN return the
corresponding pixel position rather than character
position.

You may create up to 10 fonts, number 1 through 10. Font
number 0 is reserved for BasicBasic's default font. You
create a font using the CREATEFONT command. Once you have
created a font you must select it with the SELECTFONT
command. You may get information on the currently
selected font using the FONT and FONT$ functions.

The CREATEFONT statement has a lot of arguments. However,
it is not as complex to use as it looks. Usually you are
only interested in specifying one or two things about the
font; such as height. In this case you can set all other
arguments to 0. Below is a complete description of the
CREATEFONT command.

CREATEFONT
p1,p2,p3,p4,p5,p6,p7,p8.p9.p10,p11.p12,p13,p14,p15$

p1 = Font number to be created.
A number from 1 to 10.
p2 = Font height (in pixels).
Desired height of characters. This specifies the
line spacing.
p3 = Font width
Desired width of characters. Usually set to 0
p4 = escapement
Which way the text goes.
0 - right
900 - up
1800 - right to left
2700 - down
p5 = orientation
0 = Normal
900 = tipped 90 degrees to the left
1800 = upside down
2700 = tipped 90 degrees to the right
p6 = weight
0 = don't care
100 = thin
200 = extralight
300 = light
400 = normal
500 = medium
44





BasicBasic is copyright (c) 1992 by Mark Davidsaver





600 = semibold
700 = boldface
800 = extra bold
900 = heavy
p7 = italic
When nonzero this specifies italics
p8 = underline
When nonzero this specifies underlining
p9 = strikeout
p10 = character set
0 = ANSI character set
1 = SYMBOL character set
2 = Japanese Kanji
3 = OEM character set
-> Most Windows fonts are OEM fonts (e.g. script)
p11 = output precision
Specifies how Windows should attempt to match
desired font sizes and characters with actual
fonts. Not currently defined. Make 0
p12 = clip precision
Not currently defined. Make 0.
p13 = quality
Instruction to Windows on how to match fonts.
0 - Default Quality. Don't make bigger that
desired.
1 - Draft Quality.
2 - Proof Quality. This is the best quality,
but size may be smaller than desired.
p14 = pitch and family
The two low order bits specify the pitch of the
font.
0 = Default
1 = Fixed pitch
2 = Variable
The four high order bits specify the font family.
0 = don't care
&H10 = Roman
&H20 = Swiss
&H30 = Modern
&H40 = Script
&H50 = Decorative
p15$ = "face name"
This is the name of the typeface. You do not need
to specify this. If you do it takes priority over
any other options you specify (such as height).
Examples of face names are COURIER, TMS RMN, etc.

Here is an example of a CREATEFONT command which creates a
font 60 pixels high. All other parameters are left at
default.




45





BasicBasic is copyright (c) 1992 by Mark Davidsaver





CREATEFONT 1,60,0,0,0,0,0,0,0,0,0,0,0,0,""

To print with this font you would first have to select it.

SELECTFONT 1


When you create a font Windows tries to match the
characteristics you specify in the CREATEFONT command. It
may not be able to in all cases. Perhaps you specify an
incompatible height and width. In these cases Windows
gets as close as it can. If some parameter is important
to your application you should check to make sure the font
you created meets your requirements. Using the FONT
function you can examine the selected font.

FONT(n)

n returns
--- ----------------------------------------------
1 character height
2 Ascent
3 Descent
4 Internal Leading
5 Extern Leading
6 Average Character Width
7 Maximum Character Width
8 Weight
9 Italic
10 Underline
11 Strikeout
12 First character
13 Last character
14 Default character
15 Break character
16 Pitch and Family
17 Character set
18 Overhang
19 Digitized Aspect x
20 Digitized Aspect y

There is another function which will return the face name.

FONT$(n)

n returns
--- ----------------------------------------
1 face name



If you need additional information on fonts (or Windows
programming in general), a useful reference is 'Windows
API Bible' by James L. Conger.
46





BasicBasic is copyright (c) 1992 by Mark Davidsaver



























































47





BasicBasic is copyright (c) 1992 by Mark Davidsaver







CHAINING AND COMMON
-------------------------------------------------------

Here are examples of two programs, CHAIN1 and CHAIN2,
which pass variables back and forth in common.


CHAIN1

common a,b,c,d$(),c()
if a=0 then
cls
a=1
dim d$(10)
dim c(20)
d$(5)="This is d$(5)"
end if
print "press any key to go to chain 2"
100
a$=inkey$
if a$="" then goto 100
chain "chain2.exe"


CHAIN2

common a,b,c,d$(),c()
b=b+1
print "this is chain 2"
print "b=";b;
print d$(5)
input z
chain "chain1.exe"



















48





BasicBasic is copyright (c) 1992 by Mark Davidsaver






DEFAULT WINDOWS FONT
-------------------------------------------------------

The following discussion is current for Windows Version
3.1. The concepts discussed are applicable for Version
3.0, however, font file names are different for that
version. This section is only relevant when running in
screen MODE 0 (the default).

BasicBasic selects the OEM Fixed font closest in size to
the system font size used in menus, buttons, etc. If you
desire a different font size when running a BasicBasic
program you can select from available fonts in the System
Menu. You may also mark a given font size to be the new
default for that program.

Depending on how you configured your system there may be
only one OEM font installed. Windows 3.1 comes with an
assortment of OEM fonts. The file DOSAPP.FON contains the
fonts used by Windows to run DOS in a window and are good
for use with BasicBasic. If this file is not in you
windows system directory (e.g. WINDOWS\SYSTEM) then your
can copy it from your distributions disks and then use the
Control Panel Fonts accessory to install them (These fonts
have the name 'MS-DOS CP 437').

IMPORTANT INFORMATION FOR 386 ENHANCED MODE: If you use
the MS-DOS prompt in 386 Enhanced mode you will need to
make a change in your SYSTEM.INI file to use multiple size
fonts in BasicBasic. As mentioned previously Windows does
not normally permanently install the fonts from
DOSAPP.FON. As was indicated you can do this from the
Control Panel Fonts accessory. HOWEVER, you will find
that each time you EXIT the MS-DOS prompt these fonts will
be REMOVED from the system. This is because Windows does
not expect these fonts to be present and there is a
control line in SYSTEM.INI which explicitly tells it to
load and unload them when running the MS-DOS prompt. Once
you have installed these fonts you can keep Windows from
un-installing them by removing the following line from the
[386Enh] section of SYSTEM.INI:

WOAFONT=DOSAPP.FON


FONTS AND BUTTONS: This discussion applies only to buttons
which are defined by the user to be one line high. If you
select a font smaller than the system font for use in a
BasicBasic program the text in any buttons you have would
be too crowded in the button space available. BasicBasic
corrects this problem in one of two ways. 1) If you
system font is only slightly larger than the font selected
in BasicBasic then any text in the buttons will be made
49





BasicBasic is copyright (c) 1992 by Mark Davidsaver





all upper case so no 'descenders' will be outside the
button area. 2) If the system font is quite a bit larger
than the selected font then BasicBasic will not use the
standard Windows button design. Instead it will draw a
'simplified' button which can hold the small text of the
font.
















































50





BasicBasic is copyright (c) 1992 by Mark Davidsaver






ERROR MESSAGES
-------------------------------------------------------

Compile errors will give a description of the problem and
display the line where the error occurred.

Runtime errors are divided into two classes. Fatal errors
always cause execution of the program to cease.
Recoverable errors cause program execution to cease if
SETERRLEVEL is 7, overwise execution continues and the
error number is placed in the system variable ERR.
SETERRLEVEL 7 is the default.

When runtime errors are displayed they are accompanied by
a runtime address. The compiler will optionally output a
list of runtime addresses for each statement. These
addresses will be contained in a file with the same name
as the source file and an extension of .TMP. In Windows
you select debug output by selecting the Debug Output box.
In the DOS version of the compiler you select debug output
by putting a /D in the command line (e.g. BB MYPROG /D).

Fatal Errors:

error number description
------------ -----------

236 Out of memory
503 READ is attempting to read wrong kind
of data.
501
...
522 Internal runtime errors.
523 Wrong number of array elements or
array not dimensioned.
524 Out of free space.
525 Out of string space.

Recoverable Errors:

1000 Error attempting to open file
1001 Attempt to read past end of file
1002 File not open
1003 File read error (probably hardware)
1004 ASC function on empty string
1005 Divide by zero
1006 Out of data during READ
1007 File already open
1008 No available file control block
1009 Error attempting to open file
1010 File mode error on read
1011 File mode error on write
1012 Bad file number
51





BasicBasic is copyright (c) 1992 by Mark Davidsaver





1013 Path not found
1014 RMDIR error
1015 MKDIR error
1016 KILL error
1017 FILE BUFFER ERROR
1018 INVALID FIELD DATA
1019 FIELD OVERFLOW
1020 FILE ERROR
1021 COMMUNICATIONS OPEN ERROR
1022 CREATE BUTTON ERROR
1023 BAD SCREEN MODE IN SCREEN COMMAND
1025 GRAPHICS GET ARRAY ERROR
1026 GRAPHICS PUT ARRAY ERROR
1027 CREATE FONT ERROR
1028 NOT IN CORRECT SCREEN MODE
1029 INVALID COLOR/COLOR ATTRIBUTE
1030 ILLEGAL FONT NUMBER
1031 FONT NOT DEFINE




































52





BasicBasic is copyright (c) 1992 by Mark Davidsaver






KEYBOARD CODES
-------------------------------------------------------

The following table shows the key codes returned by the
INKEY$ function. These key codes are returned as 1 byte.

KEY DECIMAL KEY DECIMAL KEY DECIMAL
KEY CODE KEY CODE KEY CODE
ESC 27 BKSP 8
1 49 ! 33 TAB 9
2 50 @ 64 ENTER 13
3 51 # 35 SPACE 32
4 52 $ 36
5 53 % 37
6 54 ^ 94
7 55 & 38
8 56 * 42
9 57 ( 40
0 48 ) 41
- 45 _ 95
= 61 + 43

KEY DECIMAL KEY DECIMAL KEY DECIMAL
KEY CODE KEY CODE KEY CODE
A 65 a 97
B 66 b 98
C 67 c 99
D 68 d 100
E 69 e 101
F 70 f 102
G 71 g 103
H 72 h 104
I 73 i 105
J 74 j 106
K 75 k 107
L 76 l 108
M 77 m 109
N 78 n 110
O 79 o 111
P 80 p 112
Q 81 q 113
R 82 r 114
S 83 s 115
T 84 t 116
U 85 u 117
V 86 v 118
W 87 w 119
X 88 x 120
Y 89 y 121
Z 90 z 122



53





BasicBasic is copyright (c) 1992 by Mark Davidsaver





The following table shows the extended key codes returned
by the INKEY$ function. These key codes are returned as 2
characters. In this case the first character will be 0.

KEY DECIMAL
KEY CODE
---- ------
F1 0 59
F2 0 60
F3 0 61
F4 0 62
F5 0 63
F6 0 64
F7 0 65
F8 0 66
F9 0 67
F10 0 68

CTRL-F1 0 94
CTRL-F2 0 95
CTRL-F3 0 96
CTRL-F4 0 97
CTRL-F5 0 98
CTRL-F6 0 99
CTRL-F7 0 100
CTRL-F8 0 101
CTRL-F9 0 102
CTRL-F10 0 103
SHIFT-F1 0 84
SHIFT-F2 0 85
SHIFT-F3 0 86
SHIFT-F4 0 87
SHIFT-F5 0 88
SHIFT-F6 0 89
SHIFT-F7 0 90
SHIFT-F8 0 91
SHIFT-F9 0 92
SHIFT-F10 0 93
HOME 0 71
UP ARROW 0 72
PGUP 0 73
LEFT ARROW 0 75
RIGHT ARR 0 77
END 0 79
DOWN ARROW 0 80
PGDN 0 81
INS 0 82
DEL 0 83
CTRL-HOME 0 119
CTRL-PGUP 0 132
CTRL-LEFT 0 115
CTRL-RIGHT 0 116
CTRL-END 0 117
CTRL-PGDN 0 118
54





BasicBasic is copyright (c) 1992 by Mark Davidsaver







Windows is a registered trademark of Microsoft
Corporation.


















































55