Programming Just Basic Tutorials PDF
Programming Just Basic Tutorials PDF
Top Next
Just BASIC is derived from Liberty BASIC, which is our commercial programming language. Here are some
of the great features of Just BASIC!
FREE to use for personal or commercial programming
Syntax coloring code editor
Create simple text mode programs or GUI applications
Create standalone programs
Includes a great source level debugger, including breakpoints
A built-in sprite engine for creating animation
Plays MIDI music and wave audio files
Includes a GUI forms editor written in Just BASIC - You can customize it!
Support RS-232 serial ports
"Windows is a registered trademark of Microsoft Corporation in the United States and other countries."
Overview of Just BASIC
Previous Top Next
Welcome to our Just BASIC overview. In this section we will introduce you to:
UNREGISTERED
What's New VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
What's new in this update of Just BASIC.
UNREGISTERED VERSION
The Just BASIC Editor OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This is the place where BASIC programs are written and compiled.
Editor Preferences
How to configure the Just BASIC editor.
Writing Programs
Getting started!
Form Designer
Creating windows with the visual designer called Freeform-J.
GUI Programming
Using windows and controls such as buttons, textboxes, etc.
Using Inkey$
Trapping and evaluating keyboard input.
Error Messages
Understanding the errors that halt program execution.
print 1.2345e-4
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
- Updated the toolbar icons in the editor and debugger for a fresh looking UI.
- Improved the parser making it tolerant of spaces between identifiers and a ( characters. For example,
some other BASICs allow the following:
Now Just BASIC also allows this kind of formatting. We did this to make it easier for people coming from
other dialects of BASIC.
- When run or debug is invoked and there is a selection in the editor a popup notice now asks if you really
want to run only the selected code. Answering no runs the entire program.
Installing and Uninstalling Just BASIC
Previous Top Next
To install Just BASIC, simply run the setup program. Either accept the default installation directory (folder),
or specify another directory (folder). Just BASIC will be installed in this folder. Subfolders containing files
needed by Just BASIC will be installed in the main Just BASIC directory. Do not modify these subfolders or
the files contained in them.
To uninstall Just BASIC, run "uninstall.exe" which is found in the folder containing Just BASIC. This folder
also contains a file called "uninstall.ini". Be careful not to delete or modify "uninstall.ini", because it contains
the information about the installation that will be used by the uninstall program.
When you start Just BASIC, you will see a window like this:
This is where code is written, and this is where you will spend most of your time when writing Just BASIC
programs. Notice the various pull-down menus along the top of the window. These are for loading and
saving files, editing, running/debugging, setting up configuration, and getting help.
Running a Just BASIC program is easy. Select the Run menu and mouse click on the Run item, as
illustrated below. You can also run a program by clicking the button on the toolbar that looks like a blue,
running man, or by pressing the "Shift" key and leaving it down while pressing the "F5" key.
Now Just BASIC will take a few seconds to compile and run the drawing program (some computers will take
longer than others). When it is finished compiling, a window belonging to the drawing program will appear:
Let's try drawing a little something with Just Draw!
Feel free to play with Just Draw, and, when you're done close its window.
Notification:
Confirm on exit of Just BASIC - This causes Just BASIC to ask "Are you sure?" when you try to close
down the Just BASIC editor.
Display execution notice - This causes Just BASIC to display an execution complete notice in a
program's main window (if it has one) when it is finished running.
Starting up:
Start Just BASIC Editor full-screen - This causes Just BASIC to open the editor so that it fills the whole
screen whenever Just BASIC is started up.
Load on startup:
No file - This causes Just BASIC to start with no text in the editor, and a filename of untitled.bas.
Most recent file - This causes Just BASIC to start with the file the user was editing when it was last shut
down.
This file - This causes Just BASIC to start with the file specified in the text field.
Compiling:
Show Compile Progress Dialog - This causes a popup dialog to appear when compiling for Run, Debug,
Lite Debug, or Make TKN file. The user can press a cancel button on the dialog to abort the compile
action.
Create *.BAK File On Run/Debug - This activates a backup mechanism so that every time a program is
run, it is also backed up into a file of the same name, but with a BAK extension. The user can also
specify where to save these files by typing the location into the textbox provided. As an example, a path
to a different hard drive could be specified as protection against hard drive failure.
Environment:
Use Syntax Coloring - This toggles the editor's syntax coloring mechanism. Check this box to see color
syntax in the editor, or uncheck it to use the system default colors for text.
Enable Auto Indenting - This feature causes the Just BASIC editor to copy the level of indenting of the
current line to a new line when Enter is pressed. It also has some support for back-tabbing.
Add 'Kill BASIC Apps' to all Windows - This adds a special menu item to the system menu of each
window in the Just BASIC environment (this menu item can also be found in the Just BASIC editor Run
menu). This feature is useful if your BASIC program will not close or shut down, because it allows you to
kill any BASIC program started from the Just BASIC editor.
Main window columns/rows - This sets the default size of the main window for any BASIC program
started from the Just BASIC editor.
Source filename extension - This specifies the filename extension to use for BASIC programs. The
default is BAS, but the user can change it to something else if desired. This is especially useful to
prevent filename collision if the programmer also uses other versions of BASIC or other applications that
use BAS as a filename extension.
Reload File on Activate - When this option is set, Just BASIC will check to see if a newer version of the
UNREGISTERED VERSION
currently loaded OFand
file exists CHM
loadTO PDF
it into the CONVERTER By THETA-SOFTWARE
editor, replacing what is there. This only happens on
activation of the editor, meaning that some window other than the Just BASIC editor was made active
(another editor or GUI drawing program perhaps), and then the editor is made the active window again by
clicking on it or by bringing it to the front in some other fashion (pressing Alt-Tab for example). Why this
is useful: Some programmers may prefer to use their favorite text editor to write code, saving the code
when they are ready to try running or debugging it. Just BASIC will be open on that file, so after they
UNREGISTERED
save in theVERSION
other editor OF
and CHM
switch TO PDF
to Just CONVERTER
BASIC, By on
with Reload File THETA-SOFTWARE
Activate the newest saved version
of the file is automatically reloaded into Just BASIC, and all that is needed to run it is to use the Run
menu or to press Shift+F5.
The Just BASIC INI file
Previous Top Next
Just BASIC uses a file called justbasic1.ini to store preferences. Even the application runtime engine uses
some of the information in this file (if it finds the file on startup). Here is a detailed description of its format
(descriptive comments are not part of the file information):
The runtime engine will use the default values for editfont, printfont, and for the mainwin columns and rows.
Writing your own Programs
Previous Top Next
Once you have loaded Just BASIC, you can write your own programs. Click on the "File" menu and then
"New File." You see this:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Now type a simple program. Press enter, and then type this line:
The Form Designer, "Freeform-J" is a utility that allows you to lay out your program windows in a graphical
way. You can simply click and drag with the mouse to add controls to a window, move them, and size them.
UNREGISTERED
When the lookVERSION OFisCHM
of the window TO PDF
satisfactory, CONVERTER
you may By THETA-SOFTWARE
save the template for future use. You may also choose
to produce the code to create this window, or choose to produce the code to create the window, plus an
outline that includes stubs for all of the controls included in the window.
Freeform-J is included in code form as well as in tokenized form. You can run the tokenized version from the
RUN menu. Freeform-J is open source software. Feel free to modify it to suit your own needs and
UNREGISTERED
preferences. VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Using the Debugger
Previous Top Next
for x = 1 to 1000
print x
next x
Now click on the debug button. The program runs and a special "Debugging" window also
appears. Position the two windows so that you can see them both. Now focus on the debugger:
Notice the pane on the top. This lists your program's variables. There's a lot of information in there already
because each program comes with some special variables already declared. Scroll down to the bottom of
the list where the variable named x is located. Focus on this variable for this example:
-Resume runs your program at full speed in the debugger. While in this mode, you won't see variables
change or program source code highlighted.
-Stop will cause your program to stop, and it will highlight the line where it stopped, and it will show the
current variable contents
-Step Into will execute the next line of code. If the next line is inside a subroutine or function it will follow
execution into the subroutine or function.
-Step Over will execute the next line of code. It will not step into subroutines or functions, but skips over
them.
-Step Out will run until the current subroutine or function exits, and then stops to show the next line of code
and variables.
-Animate runs your program, showing each line as it executes, and also updating variables as it runs.
Click on the "Step Into" button. You'll see that the first line of code is executed. The the variable x is no
longer 0, but 1. Also the next line of code is highlighted:
Now click on the "Step Into" button again. Notice that the value of x gets printed to the program window,
and also the next line of code is highlighted in the debugger:
Click a few more times on the "Step Into" button until the value of x is 3 or maybe 4. The "Step Into" button
must be pressed each time you want the program to execute a new line of code. Now click on the
"Animate" button. This mode causes the program to execute, while still documenting the current line of
code and the values of variables in the debugging window. This time you'll see the program running really
fast, and printing lots of numbers. Quickly press the "Step Into" button again to stop the program. The
program will stop executing and you can see the current values for variables and the line that is to be
executed next:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Press the "Resume" button but get ready to press the "Step Into" button again. "Resume" mode executes
the code at normal speed and it doesn't document anything in the panes of the debugging window. The
numbers will start printing really quickly in the program window, but the debugger doesn't show any activity
at all. You should still be able to click on the "Step Into" button again before the count reaches 1000. The
debugger again shows you the current state of the program.
Close the debugger. This will also close the program window.
Creating a tokenized file
Previous Top Next
Creating a *.tkn file from a *.bas source file, makes a file that:
Now pull down the "Run" menu and select "Make *.TKN File", for instance:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
When the file is ready, Just BASIC will prompt you to enter a filename in place of the default (draw1.tkn in
this case):
Once the file has been saved to disk, you run the .TKN file from within Just BASIC. Pull down the "Run"
menu and select "Run *.TKN File" as shown:
A file dialog will be displayed containing a list of .TKN files. Select the draw1.tkn file as shown and click on
Ok.
You can also run the TKN file with the Runtime Engine .
Using the Runtime Engine
Previous Top Next
The runtime engine will allow you to create standalone programs from your Just BASIC *.TKN files. This
means that your programs can be run on computers that do not have the Just BASIC language installed.
The runtime engine will automatically run a *.TKN file of the same filename as the runtime engine. If you
make a copy of JBRUN101.EXE named MYPROG.EXE, then you must name your *.TKN file as
MYPROG.TKN.
Using JBRUN101.EXE
First make a *.TKN file from your *.BAS file (see Creating a Tokenized File ).
a) That you limit the files that you distribute to the list below. These files can be found in the directory in
which you have installed Just BASIC. If you cannot see all of these files in "My Computer" or "Windows
Explorer", it is likely that your folder options are configured to hide system files. Go to the TOOLS menu of
Explorer and choose FOLDER OPTIONS. Click the VIEW tab and look for the option to "Show all files" in the
"Hidden Files" section. Be sure that this option is checked. Here is a list of the files:
vbas31w.sll
vgui31w.sll
voflr31w.sll
vthk31w.dll
vtk1631w.dll
vtk3231w.dll
vvm31w.dll
vvmt31w.dll
JBRUN101.EXE
b)You must rename a copy of JBRUN101.EXE to your liking. This is recommended. Try to create a unique
name so that it will be unlikely for any File Manager associations to conflict. If you rename JBRUN101.EXE
to MYPROG.EXE, then renaming your *.TKN file to MYPROG.TKN will cause it to be automatically run when
the runtime engine starts.
Important: Make sure that when your program is finished running that it terminates properly with an
END statement. Otherwise your program's windows may all be closed, giving the illusion that it has
stopped running.
You may use a third-party editor to create and modify Just BASIC code. You can even write your own code
editor in Just BASIC! In order to run the code with Just BASIC from another program, include the filename
of the desired program in the command line.
Examples:
or
Just BASIC has a special variable named Inkey$ which can be used to fetch keys pressed. This only
works with the graphicbox and with windows opened for graphics. Graphics controls handle an event
UNREGISTERED VERSION
called characterInput, OF
which CHM
copies TO PDF codes
pressed-key CONVERTER By variable.
into the Inkey$ THETA-SOFTWARE
See Graphics Commands ,
Inkey$ , Reading Mouse Events and Keystrokes , and Using Virtual Key Contants with Inkey$ for more
details. Here is a very short program demonstrating Inkey$:
'Inkey$ example
print "Keys pressed:"
UNREGISTERED VERSION
open "Inkey$ OF CHM
example" TOgraphics
for PDF CONVERTER
as #graph By THETA-SOFTWARE
print #graph, "when characterInput [keyPressed]"
print #graph, "trapclose [quit]"
[loopHere]
'make sure #graph has input focus
print #graph, "setfocus"
'scan for events
scan
goto [loopHere]
[keyPressed]
key$ = Inkey$
if len(key$) < 2 then
print "pressed: "; key$
else
print "Unhandled special key"
end if
goto [loopHere]
[quit]
print "Quitting"
close #graph
end
Using virtual key constants with Inkey$
Previous Top Next
Keyboard input can only be trapped in graphics windows or graphicboxes. When a key is pressed, the
information is stored in the variable Inkey$. To check for keypresses, send the command "when
characterInput [branchLabel]" to the graphics window or graphicbox and evaluate Inkey$ at the designated
branch label.
Special keys like Alt, Ctrl, Shift, the Arrow keys, etc. are not coded like the letters, numbers and other
symbols. They have special values, and are preceded by a value of 32 (or less) when they are trapped by
Inkey$. Windows has values defined for these special keys, which are expressed in virtual key constants.
You can use these constants (and other special Windows constants) in your Just BASIC programs. See
also: Graphics Commands Inkey$ , Reading Mouse and Keyboard Input , and Using Inkey$ . (See
Inkey$ for a discussion of the meaning of the first character of Inkey$ when it is longer than one
character.)
Virtual Keys
A virtual key is the key that is actually pressed on the keyboard. The VK value for a letter, say 'a' is the
same for lower case 'a' and upper case 'A' because it refers to the key pressed on the keyboard, not to the
ASCII value of the input. Most keys have a graphical representation. Pressing the 'a' key in a text window
causes the letter 'a' to be displayed in the window. There are some keys that do not have a graphical
representation. It is necessary to use Virtual Key Codes to discover which of these keys has been
pressed. They include the arrow keys, the F-keys, Shift, Ctrl, Alt, Del, etc.
[loopHere]
'make sure #graph has input focus
print #graph, "setfocus"
'scan for events
scan
goto [loopHere]
[keyPressed]
key$ = left$(Inkey$, 2)
if len(key$) < 2 then
print "pressed: "; key$
else
if right$(key$, 1) = ctrl$ then
print "CTRL was pressed"
else
print "Unhandled special key"
end if
end if
goto [loopHere]
[quit]
print "Quitting"
close #graph
end
UNREGISTERED VERSION
Some other virtual OF
key code CHM TO PDF CONVERTER By THETA-SOFTWARE
constants:
Sometimes when using Just BASIC, there are error messages presented while compiling (called compile-
time errors) and while running a program (called run-time errors).
Syntax error - This means that some error was made while typing in a BASIC statement. You should
examine the line and look for typing mistake.
Type mismatch error - This means that you tried to use a string where a number should be used, or a
number where a string should be used.
Branch label [exampleLabel] not found - The program tried to GOTO or GOSUB to a label that doesn't
exist.
Float divide by zero exception - The program tried to divide a number by zero, which is not possible to do.
File filename not found - This error can occur when attempting to load a bitmap image from a disk file into
memory using the LOADBMP statement, and when no file of the specified filename is found to exist.
Bitmap named bitmapname not found - This error can occur when attempting to save a bitmap from
memory to a disk file using the BMPSAVE statement, or when attempting to use the DRAWBMP command,
and a bitmap name is specified which doesn't exist in the program's memory.
Control type fonts are set with: !FONT face_Name width height - An error was made specifying the font for
a control (controls which return this error include button, textbox, radiobutton, checkbox).
Errors when using serial communications - There are a handful of run-time error messages which terminate
program execution. These usually correlate to API function call failures that occur when attempting
different operations. In this case, the error is reported by Windows, but the description of the reported error
is generated by Just BASIC. Here is a list of the error messages:
The following run-time errors are indications of more subtle problems in Just BASIC. If you see one of
these errors, send email to carlg@Justbasic.com describing in as much detail how the error happened. If
you have BASIC code that can reproduce the error, please include it in your message.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Index: n is outside collection bounds
The collection is empty
Object is not in the collection
Sometimes the Just BASIC compiler finds a problem with your code, and it will stop and give you an error
message of some kind. Usually this will appear on the status line at the bottom of the Just BASIC editor
window. At other times you may see a popup error notice when running a program that you've written.
There are a variety of programmer errors which can give rise to such error messages. For example,
perhaps a program tries to divide a number by zero (which is mathematically impossible to do), or maybe a
program closes a file, and then tries to close it again (it isn't possible to close a file that isn't open). These
kinds of programmer bugs result in a popup error message.
However, sometimes you will get a popup error notice that mentions the ERROR.LOG file. This means that
you have stumbled across a nastier sort of bug in Just BASIC itself, and Just BASIC has written something
about that bug in the ERROR.LOG file.
What should you do with the information in the ERROR.LOG file? Some people have contacted us more
than a little confused after looking at the contents of the this file. Don't worry. This information is much more
useful to us, since it contains details about the internals of Just BASIC. We have a pretty good idea what it
means. If you are so inclined, you can send it to us and we'll take a look at it and try to help you with the
bug, and also use the information to fix bugs in new releases of Just BASIC.
To do this, send email to support@Justbasic.com and explain in as much detail as you can how the error
happened. If you aren't sure how it happened, see if you can make the error happen again. It can be very
hard, or nearly impossible to fix bugs when they cannot be recreated. Sometimes it helps us to figure out the
cause of the error when we have access to the source code and other files that you were using when the
error happened. If you can, please provide us with these things so that we can serve you best. We realize
of course that sometimes you may not want to share your code and files for privacy reasons or because your
company policy may forbid it, and this is perfectly understandable.
Now that you have a better understanding of what ERROR.LOG is and how to make use of it, you will be
able to help us improve the quality of the Just BASIC programming language!
TroubleShooting
Previous Top Next
- Video drivers. A major problem with environments like Windows video drivers are sometimes immature
UNREGISTERED VERSION
and/or incompletely OF CHM
implemented TO PDF
according CONVERTER
to spec. Try to get theBy THETA-SOFTWARE
most recent version of the Windows
drivers for your video card. Another way to test for this condition is to try the standard VGA drivers that
come with Windows to see if this solves the problem.
If when using Just BASIC you get an error notice that mentions the error.log file, you should send us a copy
of your error.log file (at least the last entry which causes the error). This will help us to determine what is
going wrong so we can tell you how to solve the trouble.
Every once in a while someone reports experiencing a Class already exists(OS Error 16r582) error. There
is no fix for this at this time. Sometimes it is necessary to reboot to eliminate this condition.
Logical Line Extension
Previous Top Next
Just BASIC supports a technique called logical-line-extension, which allows one line of code to be split over
several lines of text in the editor. For example:
A line can get long and difficult to read! Consider the following equivalent.
When the line is broken up with the _ character, the code is more readable.
The NOMAINWIN command
Previous Top Next
When a Just BASIC program is run, a simple text window called the mainwin appears. It can be used to
display text and to ask the user for input. To suppress the mainwin, a nomainwin statement is used:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
nomainwin 'don't open a mainwin
menu #draw, "Draw", "Draw now", [drawNow]
open "No man's land, er... nomainwin" for graphics as #draw
print #draw, "trapclose [quit]"
wait
UNREGISTERED
[drawNow] VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
print #draw, "cls ; home ; down ; north"
for x = 1 to 100
print #draw, "turn 122 ; go "; str$(x*2)
next x
print #draw, "flush"
wait
[quit]
confirm "Do you want to quit Buttons?"; quit$
if quit$ = "no" then wait
close #draw
end
The mainwin can be used when a program is under development. If a program locks up or crashes, it can
still be closed by clsoing the mainwin. It is important that a program have trapclose handlers for all of its
windows when the nomainwin command is used, otherwise the program may still be running with no way to
close it. All programs should finish executing with an END statement (like the example above) to ensure
that programs actually do clean up by themselves.
If a program continues running with no way to close it, it may be ended by clicking on the Run menu on the
Just BASIC editor and selecting Kill BASIC Programs.
Functions and Subroutines
Previous Top Next
See also: Function , Sub , Branch Labels, GOTO and GOSUB , GOSUB , RETURN , GOTO , GLOBAL ,
BYREF
Just BASIC supports user defined functions and subroutines. They look similar to their QBASIC
equivalents:
and...
A user-defined function such as the one above can be treated like any built-in function:
Subroutines in Just BASIC are accessed using the CALL statement. For example:
The variable scoping in subroutines and functions is local. This means that by default, the names given to
variables inside the definition of a subroutine or function are only meaningful inside that definition. For
example, a variable named "counter" can exist in the main program code. The program can use a function
which also contains a variable named "counter" in its code. When the function is used, the "counter"
variable in the calling code doesn't lose its value when the function changes the value of its variable named
"counter". They are in fact different variables, although they share the same name. Variables passed into
subroutines may be passed by reference, which allows them to be changed in the subroutine or function,
and the change is reflected in the main program. For more on passing byref, please see below.
function loop(limit)
for counter = 1 to limit
next counter
loop = counter
end function
Exceptions to the variable scoping mechanism include the following things which are globally visible
everywhere in a Just BASIC program:
- Arrays
- Things with handles (files, windows, DLLs, communications ports)
- Structs
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
GLOBAL
In general, variables used in the main program code are not visible inside functions and subroutines.
Variables inside functions and subroutines are not visible in the main program. Variables declared as
GLOBAL can be seen everywhere in a program. See GLOBAL . The special system variables
lWindowWidth, WindowHeight, UpperLeftX, UpperLeftY, ForegroundColor$, BackgroundColor$,
UNREGISTERED
ListboxColor$,VERSION OF ComboboxColor$,
TextboxColor$, CHM TO PDF CONVERTER
TexteditorColor$,By THETA-SOFTWARE
DefaultDir$, Joy1x, Joy1y, Joy1z,
Joy1button1, Joy1button2, Joy2x, Joy2y, Joy2z, Joy2button1, Joy2button2, and Com now have true global
status. GLOBALS are specified and used like this:
sub openIt
statictext #it.stext, "Look Mom!", 10, 10, 70, 24
textbox #it.tbox, 90, 10, 200, 24
open title$ for window as #it
print #it.tbox, "No hands!"
end sub
NOTE: Branch labels inside functions and subroutines are not visible to code outside those functions and
subroutines. If code in the main program tries to access a branch label inside a function or subroutine, this
will cause get an error. Likewise, functions and subroutines cannot use branch labels defined outside their
scope.
We can pass variables by reference. This means that if a subroutine or function so declares, it can modify
the value of a variable passed in, and when the subroutine or function ends and execution returns to the
caller the change will be reflected in the variable that was used as a parameter in the call.
By default and without any direct instruction by the programmer, parameters passed into user defined
functions and subroutines in QBasic and Visual Basic are passed by reference. That is not true in Just
BASIC, where values are passed by value as the default. Passing by reference is only done when the
BYREF keyword is used.
function formatAndTruncateXandY$(a, b)
a = int(a)
b = int(b)
formatAndTruncateXandY$ = str$(a)+", "+str$(b)
end function
end
UNREGISTERED VERSION
'and it OF CHM
works with TO PDFtoo
subroutines CONVERTER By THETA-SOFTWARE
call capitalize "gandalf"
a$(0) = "snoopy"
call capitalize a$(0)
UNREGISTERED
end VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
See also: GOSUB , RETURN , GOTO , Functions and Subroutines , Function , Sub
Branch Labels
Just BASIC will accept numbers as branch labels. This is useful when using old BASIC code. The numbers
don't change the order of the code. The following two short programs are essentially the same:
Instead of using numeric branch labels, it is better to use alphanumeric ones, because they are descriptive
and help the programmer remember what is happening in a block of code. In Just BASIC, alphanumeric
branch labels are surrounded by square braces: [myBranchLabel] Spaces and numbers are not allowed as
part of branch label names, and names may not start with a numeral.
In QBASIC, branch labels end with a colon and looks like this: myBranchLabel:
The above program doesn't really need branch labels. It looks like this without them:
'count to ten
for x = 1 to 10
print x
next x
end
'count to ten
[startLoop]
x = x + 1
print x
if x < 10 then [startLoop]
end
'count to ten
startLoop:
x = x + 1
print x
if x < 10 then goto startLoop
end
NOTE: Branch labels inside functions and subroutines are not visible to code outside those functions and
subroutines. Likewise, functions and subroutines cannot use branch labels defined outside their scope.
GOTO
To continue program execution at a specified branch lable, issue a GOTO command. See GOTO .
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
GOTO [startLoop]
GOSUB
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
To continue program execution at a specifed GOSUB routine, issue a GOSUB command. The GOSUB
routine ends with a RETURN statement that returns program execution to the line of code following the
GOSUB command. See GOSUB , RETURN .
GOSUB [initialize]
Conditional Statements
Previous Top Next
Description:
The IF...THEN statement provides a way to change program flow based on a test expression. For example,
the following line directs program execution to branch label [soundAlarm] if fuel runs low.
Another way to control program flow is to use the IF...THEN...ELSE statement. This extended form of
IF...THEN adds expressiveness and simplifies coding of some logical decision-making software. Here is an
example of its usefulness.
Consider:
[retry]
input "Please choose mode, (N)ovice or e(X)pert?"; mode$
if len(mode$) = 0 then print "Invalid entry! Retry" : goto [retry]
mode$ = left$(mode$, 1)
if instr("NnXx", mode$) = 0 then print "Invalid entry! Retry" : goto [retry]
if instr("Nn", mode$) > 0 then print "Novice mode" : goto [main]
print "eXpert mode"
[main]
print "Main Selection Menu"
Any number of variations on these formats are permissible. The (a < b) BOOLEAN expression is of course
only a simple example chosen for convenience. It must be replaced with the correct expression to suit the
problem.
IF...THEN...END IF is another form using what are called conditional blocks. This allows great control over
UNREGISTERED VERSION
the flow of program OF
decision CHM Here
making. TO PDF CONVERTER
is an example By THETA-SOFTWARE
of code using blocks.
if qtySubdirs = 0 then
print "None."
goto [noSubs]
end if
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
A block is merely one or more lines of code that are executed as a result of a conditional test. There is one
block in the example above, and it is executed if qtySubdirs = 0.
if qtySubdirs = 0 then
print "None."
else
print "Count of subdirectories: "; qtySubdirs
end if
This type of coding is easy to read and understand. There are two blocks in this example. One is executed
if qtySubdirs = 0, and one is executed if qtySubdirs is not equal to 0. Only one of the two blocks will be
executed (never both as a result of the same test).
if verbose = 1 then
if qtySubdirs = 0 then
print "None."
else
print "Count of subdirectories: "; qtySubdirs
end if
end if
In the example above, if the verbose flag is set to 1 (true), then display something, or else skip the display
code entirely.
or like:
The elseif keyword is not supported. Here is an example using elseif (QBasic):
'QBasic only
if sis boom bah then
print "Yippie!"
elseif la dee da then
print "So what!"
end if
Many BASICs have a Select Case statement, and Just BASIC has that capability also. It is a good
alternative when many possible conditions must be evaluated and acted upon. The Select Case
UNREGISTERED VERSION
construction also provides OF CHM
a Case ElseTO PDF CONVERTER
statement for implementingBy THETA-SOFTWARE
a routine when the evaluated condition
meets none of the cases listed. For more, see SELECT CASE .
SELECT CASE is a construction for evaluating and acting on sets of conditions. The syntax for Select Case
is:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
SELECT CASE var
CASE x
'basic code
'goes here
CASE y
'basic code
'goes here
CASE z
'basic code
'goes here
CASE else
'basic code
'goes here
END SELECT
Details:
SELECT CASE var - defines the beginning of the construct. It is followed by the name variable that will be
evaluated. The variable can be a numeric variable or a string variable, or an expression such as
"a+b".
CASE value - following the SELECT CASE statement, are individual CASE statements, specifying the
conditions to evaluate for the selected variable. Code after the "case" statement is executed if that particular
case evaluates to TRUE. There is no limit to the number of conditions that can be used for evaluation.
CASE ELSE - defines a block of code to be executed if the selected value does not fulfil any other CASE
statements.
Example usage:
num = 3
three
Strings
SELECT CASE can also evaluate string expressions in a similar way to numeric expressions.
String example:
var$="blue"
Once one of the CASEs has been met, no other case statements are evaluated. In the following example,
since the value meets the condition of the first CASE statement, the second CASE statement isn't
considered, even though the value meets that condition also.
num = 3
3, 5, 10
'correct:
value = 58
case else
print "Not evaluated"
end select
OR:
select case
case day = today
if time < 12 then
do something
else
something else
end if
case month = Jan
do something
case moon = full
do something
end select
If the expression "value" is placed after "select case", then none of the CASE statements is met, so CASE
ELSE is triggered, which prints "Not evaluated". The expression must be omitted to evaluate multiple values
in a SELECT CASE statement:
'wrong:
select case value
'correct:
select case
Nested statements
Nested select case statements may be used. Example:
10010
The first digit on the RIGHT side of the number is in the one's column. The second digit from the right is in
UNREGISTERED VERSION
the two's column, OFthe
then comes CHM TO
four's PDF the
column, CONVERTER
eight's column,By
theTHETA-SOFTWARE
sixteen's column and so on. Each
column contains a "bit", or binary digit.
16 8 4 2 1
This example binary number, "10010", converted to a decimal number, evaluates like this.
16 8 4 2 1
1 0 0 1 0
16 * 1 = 16
8 * 0 = 0
4 * 0 = 0
2 * 1 = 2
1 * 0 = 0
_________________________________
total = 18 in decimal numbers
AND
The AND operator will set a bit only if both input bits are set.
'Bitwise AND
'This operation sets a bit only if
'both inputs have the bit set.
'16 8 4 2 1 '
'-------------- '
' 0 0 1 1 1 ' 7 in binary
' 0 1 0 1 1 ' 11 in binary
'
' ^ ^ ' These are the place values where both
numbers are 1.
' ' Hence, 2 + 1 = 3
OR
The OR operator will set a bit if either input bit is set.
'Bitwise OR
'This operation sets a bit if
'either input has the bit set.
'16 8 4 2 1 '
'-------------- '
' 0 0 1 1 1 ' 7 in binary
' 0 1 0 1 1 ' 11 in binary
'
' ^ ^ ^ ^ ' These are the place values where
either number has a 1.
' ' Hence, 8 + 4 + 2 + 1 = 15
XOR
The Bitwise XOR operation sets a bit only if exactly one of the inputs has the bit set.
'Bitwise XOR
'This operation sets a bit only if
'exactly one of the inputs has the bit set.
'16 8 4 2 1 '
'-------------- '
' 0 0 1 1 1 ' 7 in binary
' 0 1 0 1 1 ' 11 in binary
'
' ^ ^ ' These are the place values
where exactly one of the
' ' numbers has a 1. Hence, 8 + 4 = 12
UNREGISTERED VERSION
The code is evaluating the OF CHM(xTO
condition < 3)PDF CONVERTER
and branching By THETA-SOFTWARE
to the [doSomething] label if the condition is
TRUE. If the value of x is 1, then the condition evaluates to TRUE and the program branches to
[doSomething]. If the value of x is 7, then the condition evaluates to FALSE and the program does NOT
branch to [doSomething].
Boolean Operators
= a = b a is equal to b
< a < b a is less than b
<= a <= b a is less than or equal to b
> a > b a is less than b
>= a >= b a is greater than or equal to b
<> a <> b a is not equal to b
Multiple Conditions
When evaluating multiple conditions, each condition must be placed inside parentheses, as in the examples
below.
AND - both conditions must be met for the test to evaluate to TRUE.
a = 2 : b = 5
If (a<4) and (b=5) then [doSomething]
In this code, (a must be less than 4) AND (b must be equal to 5) for the program to branch to
[doSomething]. Since both of these conditions are true, the program will advance to [doSomething]
a = 14 : b = 5
If (a<4) and (b=5) then [doSomething]
This similar example evaluates to FALSE because (a is not less than 4), so the program will not advance to
[doSomething]
OR - at least one of the conditions must be met for the test to evaluate to TRUE.
a = 14 : b = 5
If (a<4) OR (b=5) then [doSomething]
In this code, at least one of the conditions (a must be less than 4) OR (b must be equal to 5) must evaluate
to TRUE for the program to branch to [doSomething]. Since the example shows that (b is equal to 5), the
program will advance to [doSomething], because at least one of the conditions evaluates to TRUE.
XOR - only one of the conditions must be met for the test to evaluate to TRUE.
a = 14 : b = 5
If (a<4) XOR (b=5) then [doSomething]
In this code, only one of the conditions (a is less than 4) OR (b is to 5) must evaluate to TRUE for the
program to branch to [doSomething]. In the example, only the second condition evaluates to true, so the
program will advance to [doSomething].
a = 2 : b = 5
If (a<4) XOR (b=5) then [doSomething]
In the second XOR example, both conditions evaluate to true, so the program will NOT advance to
[doSomething].
In this code, both of the conditions (a must NOT be less than 4) AND (b must be equal to 5) must evaluate to
TRUE for the program to branch to [doSomething].
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
Just BASIC provides three constructions for looping. One is FOR/NEXT another is WHILE/WEND, and the
third is DO LOOP.
UNREGISTERED VERSION
FOR/NEXT executes OF
a loop CHM
a set TO of
number PDF CONVERTER
times, By THETA-SOFTWARE
which is determined by the starting and ending values in
the FOR statement and by the size of the STEP. For more on For...Next loops, click here .
WHILE/WEND executes a loop as long as a specified condition evaluates to TRUE. For more on
While...Wend loops, click here .
UNREGISTERED VERSION
DO LOOP provides a loop OF
that CHM
alwaysTO PDF once
executes CONVERTER
and then onlyBy THETA-SOFTWARE
loops back as long as a condition is
met. For more on DO LOOPs, click here .
WARNING: In loops, an "exit" statement is provided for instances where it is necessary to exit the loop
before the counter variable has reached its max, or the "while" condition evaluates to false. Do not attempt
to exit a loop prematurely by issuing a "goto" statement.
FOR/NEXT
The FOR . . . NEXT looping construct provides a way to execute code a specific amount of times. A starting
and ending value are specified:
for var = 1 to 10
BASIC code
next var
In this case, the BASIC code is executed 10 times, with var being 1 the first time, 2 the second, and on
through 10 the tenth time. Optionally (and usually) var is used in some calculation(s) in the BASIC code. For
example if the BASIC code is print var ^ 2, then a list of squares for var will be displayed upon execution.
The specified range could just as easily be 2 TO 20, instead of 1 TO 10, but since the loop always counts +1
at a time, the first number must be less than the second. The way around this limitation is to place STEP n
at the end of for FOR statement:
This loops 19 times returning values for index that start with 20 and end with 2. STEP can be used with both
positive and and negative numbers and it is not limited to integer values. For example:
WHILE/WEND
As shown above, Just BASIC includes a for/next looping construct. It also has a while/wend looping
construct. Here is the above program rewritten using while/wend.
'count to ten
x = 0
while x < 10
x = x + 1
print x
wend
end
One useful thing that can be done with while/wend is to wrap the boolean expression in a NOT() function,
which effectively turns while/wend into a "while condition is false" do construct:
'count to ten
while not(x = 10)
x = x + 1
print x
wend
end
DO LOOP
Just BASIC also provides a DO LOOP structure for cases when you want a loop that always executes once
and then only loops back as long as a condition is met. It will continue looping back and executing the code
as long as the booleanExpr evaluates to true. Here is the routine that counts to 10 using DO LOOP with
while and DO LOOP with until.
do
print a
a = a + 1
loop while a < 11
print
do
print b
b = b + 1
loop until b = 11
Just BASIC supports recursive subroutine and function calls. This means that a function can call itself.
When it does this it makes a copy of itself, reusing its variable names. The values are not overwritten. It is
UNREGISTERED VERSION
important to place OF CHM
an evaluation TO PDF
statement insideCONVERTER By that
a recursive function THETA-SOFTWARE
causes the function to finish and
return to the main code. Care should be taken to avoid creating an endlessly looping recursive function.
The two examples below contains an "IF...THEN" evaluation that, when met, causes the function to stop
calling itself and return control to the main program.
Now here's an example of a recursive function that returns the factorial of a number. A factorial is obtained
by taking a number and multiplying it in turn by each integer less than itself. The factorial of 5 is
5x4x3x2x1=120. The factorial of 7 is 7x6x5x4x3x2x1=5040. The numbers get big in a hurry after this. For
example, the factorial of 15 is 1307674368000!!
'factorial
input "Compute factorial for?"; n
print factorial(n)
end
function factorial(a)
factorial = 1
if a > 1 then factorial = a*factorial(a-1)
end function
The Timer Statement
Previous Top Next
Just BASIC includes a timer statement which uses the computer's hardware timer. Most PCs have a timer
with a resolution of approximately 56 milliseconds which ticks 18 times a second. The timer allows the
addition of a clock to a program, or or it allows the program to wake up every few seconds to check for
some condition, or it can be used to control the rate of animation of a game. There are other uses as well.
The TIMER command specifies how many milliseconds to wait between timer signals. One second is 1000
milliseconds. It also specifies a routine to serve as an event handler. The timer may be turned off and
then back on.
LITERALS
UNREGISTERED
A literal valueVERSION OF
is hard-coded intoCHM TO PDF
a program. HereCONVERTER By THETA-SOFTWARE
are two literals, printed to the mainwin. The first is a
number. The second is a string of text characters.
print 57
print "Hello World"
UNREGISTERED
produces VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
57
Hello World
VARIABLES
A variable is a name used in the code that represents a string or numeric value. The value assigned to the
variable name may change as the program runs. The program can always access the current value of the
variable by refering to its name. In this example, a value of "3" is assigned to a variable called myNumber:
myNumber=3
print myNumber
produces
myNumber=17
print myNumber
produces
17
In Just BASIC variables are either string or numeric. A variable name can start with any letter and it can
contain both letters and numerals, as well as dots (for example: user.firstname). There is no practical limit
to the length of a variable name. The variable names are uppercase and lowercase sensitive, so these are
not the same variable:
supercalifragilisticexpialadocious
superCaliFragilisticExpialaDocious
As in most versions of BASIC, string variable names end in a "$" character for example:
The boast above is correct. In Just BASIC, string variables can be huge, containing as many as 2 million
characters.
Unlike some BASICs, Just BASIC does not require variables to be declared before they may be used in
code. It is importatnt to check the spelling/capitalization of variables, because variable names are case
sensitive.
GLOBAL
In general, variables used in the main program code are not visible inside functions and subroutines.
Variables inside functions and subroutines are not visible in the main program. Variables declared as
GLOBAL can be seen everywhere in a program. The special system variables like WindowWidth,
WindowHeight, etc. now have true global status. GLOBALS are specified and used like this:
Just BASIC supports single and double dimensioned arrays. These can be defined as string or numeric
arrays. The extents of the dimensions can be in excess of 2 million elements, if there is enough RAM
UNREGISTERED
available. VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Arrays that contain more than 11 elements (indexed 0 to 10) must be dimensioned before they can be used.
Arrays are dimensioned with the DIM statement.
Resizing is done to any array with the REDIM statement, but doing so will erase the contents of the array.
REDIM students$(30)
Double dimensioned arrays must always be dimensioned with the DIM statement before use.
The equal sign ( = ) is used to assign a value to an element in an array. The element is referred to by its
index number. The index may be expressed as a literal number or as a numeric variable. The element at
index 2 in the following example is filled with "John." The element at index 7 is filled with the number 12.
students$(2) = "John"
ages(7) = 12
Arrays can be used in most places where a variable or literal value can be used. To access the value of an
element in an array, the index for that element is placed inside the parentheses. In this example, the value
at index 4 is retrieved from the array:
thisKid$ = students$(4)
or
print students$(4)
for i = 1 to 30
print students$(i)
next
Input to Arrays
It is possible to use both Input and Line Input to read data from opened files directly into arrays.
'now works:
open "myfile.dat" for input as #f
input #f, itemArray$(1)
close #f
It is still necessary to READ data into a variable, then fill an array element, however:
'wrong:
read numericArray(1)
'correct:
read num1
numericArray(1) = num1
Although Just BASIC only allows arrays with one or two dimensions, arrays with three or more dimensions
can be easily simulated. To simulate an array of 10 by 10 by 10, it is possible to stack the third dimension
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
on top of the second:
function getMyArray$(x, y, z)
getMyArray$ = myArray$(x, y + z * 10)
end function
READ and DATA
Previous Top Next
DATA statements can be embedded in Just BASIC programs to make access to string and numeric data
easier. DATA is accessed by the program with the READ statement, which reads the DATA items in
sequence. The RESTORE statement causes the next READ statement to start at the first DATA statement
listed, or at the first DATA statement following a specified branch label if one is included in the RESTORE
statement. These methods can be used to put data into arrays, thus providing an easy method for filling
arrays.
DATA
The DATA statement provides a convenient way to insert data into programs. The DATA can be read once
or many times using the READ statement. A DATA statement doesn't actually perform an action when it is
encountered in the program's code.
One or more DATA statements form the whole set of data elements. For example, the data represented in
the example above can also be listed in more than one DATA statement:
READ
This fetches the next strings and/or numeric values from DATA statements in a program. The READ
statement will fetch enough items to fill the variable names that the programmer specifies. The values
fetched will be converted to fit the variables listed (string or numeric).
Example:
RESTORE
RESTORE will reset the reading of DATA statements so that the next READ will get information from the
first DATA statement in the program (or the first DATA statement in a function or subprogram, if this is
where the RESTORE is executed).
Example:
end
RESTORE [branchLabel]
end
'correct:
read num1
numericArray(1) = num1
Error Handling
An attempt to read more DATA items than are contained in the DATA lists causes the program to halt with
an error. Notice that in the examples above, an "end" tag is placed in the DATA and when it is reached,
the program stops READing DATA. This is an excellent way to prevent errors from occuring. If an end tag
or flag of some sort is not used, be sure that other checks are in place to prevent the READ statement from
trying to access more DATA items than are contained in the DATA statements.
Just BASIC supports sequential, binary and random access file operations.
See also: OPEN , Sequential Files , Binary Files , Random Access Files , CLOSE , INPUT , INPUT$ , LINE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
INPUT , PRINT
UNREGISTERED VERSION
Files can be removed with OF CHMcommand.
the KILL TO PDF CONVERTER By THETA-SOFTWARE
When a file is being read, the EOF function returns 0 if the end of the file has been reached, otherwise it
returns -1.
The drive specifications for the computer on which a program is running are contained in the special variable
Drives$ .
The directory in which a program resides on disk is contained in the special variable DefaultDir$ .
Folders, also called Directories, can be created with the MKDIR command.
Folders, also called Directories, can be removed with the RMDIR command.
Sequential Files
Sequential Files are accessed from beginning to end, sequentially. It is not possible to read or write a
piece of data to the center of the file. Files opened for INPUT can only be read. Files opened for
OUTPUT or APPEND can only be written. For more, see Sequential Files .
Binary Files
Files opened for binary access may be read or written, beginning at any location within the file. For
detailed information on using binary files, see Binary Files .
Random Files
Files opened for random access are read or written one record at a time. The length of records in the file
is determined in the OPEN statement. For detailed information on using random files see Random
Access Files .
print txt$
end
'produces
12345
12345
Sequential Files
Previous Top Next
Sequential files are opened with the OPEN statement. When they are no longer needed, or when the
program ends, they must be closed with the CLOSE statement.
UNREGISTERED
Sequential fileVERSION OFdata
access allows CHM TO
to be PDF
read fromCONVERTER
a file or written toBy THETA-SOFTWARE
a file from beginning to end. It is not
possible to read data starting in the middle of the file, nor is it possible to write data to the file starting in the
middle using sequential methods.
Data is read from a file opened for INPUT starting at the beginning of the file. Each subsequent input
statement reads the next piece of data in the file. Data is written to a file opened for OUTPUT with a PRINT
UNREGISTERED VERSION
statement starting OF CHM
at the beginning TOfile,
of the PDF andCONVERTER
each subsequentBy PRINTTHETA-SOFTWARE
statement writes data to the end
of the open file. When a file is opened for APPEND, each PRINT statement writes data to the end of the
open file.
INPUT
Files opened for INPUT can be read from. They cannot be written to. A file opened for INPUT must exist
on disk, or the program will halt with an error. See Testing For File Existence .
The INPUT statement reads a piece of data up to the next comma or carriage return. The LINE INPUT
statement reads a piece of data that contains commas that are not delimiters, and stops reading data at
the next carriage return. The INPUT$ statement reads data of a specified length from a file. Here is an
illustration of the differences between the various forms of INPUT statements.
Example Program:
'create a sample file
open "test.txt" for output as #1
print #1, "123 Sesame Street, New York, NY"
close #1
'INPUT
open "test.txt" for input as #1
INPUT #1, txt$
print "INPUT item is: ";txt$
close #1
'LINE INPUT
open "test.txt" for input as #1
LINE INPUT #1, txt$
print "LINE INPUT item is: ";txt$
close #1
'INPUT$
open "test.txt" for input as #1
txt$ = INPUT$(#1, 10) 'read 10 characters
print "INPUT$ item is: ";txt$
close #1
Produces:
INPUT item is: 123 Sesame Street
LINE INPUT item is: 123 Sesame Street, New York, NY
INPUT$ item is: 123 Sesame
OUTPUT
Files opened for OUTPUT can be written to sequentially. If a file opened for OUTPUT does not exist, it
will be created. If the file does exist on disk, the previous contents will be overwritten, and therefore lost.
Care should be taken when opening files for OUTPUT so that critical data is not accidentally erased. See
Testing For File Existence .
Data is written to a file opened for OUTPUT with a PRINT statement. A line delimiter or carriage return is
written to the file with each PRINT statement. The carriage return may be suppressed by ending the line
of code with a semi-colon.
Example Program:
'create a sample file
open "test.txt" for output as #1
Contents of file:
line one
UNREGISTERED
line twoVERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
item three item four item five
done
APPEND
Files opened for APPEND can be written to sequentially. If a file opened for APPEND does not exist, it
UNREGISTERED VERSION
will be created. OF
If the file CHM
does existTO PDFany
on disk, CONVERTER
data written to By
the THETA-SOFTWARE
file with a PRINT statement will be
added to the end. Writing data to the file works in the same way when a file is opened for APPEND as
when it is opened for OUTPUT, but rather than overwriting data contained in the file, the new data is
appended to the end of the file, but does not overwrite data previously written to the file the last time it
was opened as open for OUTPUT does.
.
Example Program:
open "test.txt" for append as #1
File Copy
A file may be copied using sequential file operations. The file to be copied is opened for INPUT. The file that
is to be a copy is then opened for OUTPUT. The contents of the original file are retrieved with the INPUT$
statement and written to the copy with the PRINT statement. Both files are then closed. Here is an
example:
To access a file in binary mode, it must be opened with the OPEN statement. When it is no longer
needed, and before the program ends, it must be closed with the CLOSE statement. See also: Filedialog
, File Operations , Path and Filename .
In binary access mode, bytes are written to the file or read from the file as characters. See Chr$( n ) .
Use the SEEK command to seek to the desired point in the file for reading or writing. This sets the file
pointer to the location specified. Use the LOC(#handle) function to retrieve the current position of the file
pointer. The current position of the file pointer is used when reading or writing data to a binary file.
Data is written to the file with the PRINT statement. Binary mode never writes line delimiters when
printing to the file. Line delimiters include carriage returns, which are chr$(13) and line feeds, which are
chr$(10).
Usage:
Example Program:
UNREGISTERED
'move theVERSION OF CHM
file pointer TO PDF
to the CONVERTER By THETA-SOFTWARE
beginning
seek #myfile, 0
To access a file in random access mode, it must be opened with the OPEN statement. When it is no longer
needed, and before the program ends, it must be closed with the CLOSE statement. See also: Filedialog ,
File Operations , Path and Filename , PUT , FIELD , GET
Random Access files consist of RECORDS. The entire file is divided into many records. Each record has
the same length. The length is specified when the file is opened with the LEN parameter. The example
below opens a file called "members.dat" and sets the record length to 256:
Reading and writing to a file opened for random access is done one record at a time. A record may be
read or written anywhere in the file. A record is read with either the GET statement, or with the GETTRIM
statement. A record is written to the file with the PUT statement. These statements are explained in more
detail below.
FIELD Statement
Each record is subdivided into "fields", each with a given length. The FIELD statement must be included
after the OPEN statement to set up the size of each of the fields. Each field is designated by a variable
name and given a specified length. When the lengths of all fields are added together, their sum must be
equal to the length that was set with the LEN parameter in the OPEN statement. In the above case, the
field lengths must total 256. A "$" character indicates that a field holds data that will be accessed as a
string. If there is no "$" character, the field will be accessed as a number. The fields for "members.dat"
might look like this:
The value after "LEN=" is 256, which is obtained by adding 90 + 110 + 50 + 6 or the total length of all the
fields in FIELD#. The FIELD statement must follow the OPEN statement and must be used before trying to
read or write data to the file with GET or PUT.
PUT
PUT #handle, number
This statement is used to write the data that is contained in the variables listed in the FIELD statement to
the specified record number. Records in RANDOM files are numbered beginning at 1, not 0. If the length
of a variable in a given field is shorter than the field length specified, blank spaces are added to pad it. If
the length of the variable is larger, it will be truncated to the length specified in the FIELD statement. To
add this data as RECORD number 3 to the file referenced above:
PUT #1, 3
GET
GET #handle, number
UNREGISTERED VERSION
This statement OF CHM
reads an entire record TO PDF
and fills theCONVERTER
variables listed inBy
theTHETA-SOFTWARE
FIELD statement.
GET #1,3
and so on.
Testing for File Existence
Previous Top Next
Here is a short user-defined function which can be used to test if a file exists on disk. It is important to
know if a file exists because attempting to access a nonexistent file can cause a program to crash.
If the file is to be in the default directory, and named users.dat this example shows how to test for its
existence with the fileExists function:
The dim info$(10, 10) statement is important because the files command in the function needs to have a
double dimensioned array ready to accept its list of files and their information. See FILES .
Path and Filename
Previous Top Next
References to a complete path and filename indicate that the drive letter and all folders and sub folders are
UNREGISTERED
included in theVERSION OF CHM
file specification. TO PDF
A complete pathCONVERTER By THETA-SOFTWARE
and filename is returned by the FILEDIALOG . An
example of a complete path and filename is as follows:
C:DocumentsProgramsbas
Filename Alone
UNREGISTERED
References toVERSION OF CHM
a filename without path TO PDF CONVERTER
information indicate that the By
diskTHETA-SOFTWARE
filename is used with no drive or
folder information. In Just BASIC, use of a filename without path information assumes that the file exists on
disk in the DefaultDir$ . An example is as follows:
mygame.bas
Sub Folder
A file that exists in a subfolder of the DefaultDir$ is written by first identifying the sub folder(s), each followed
by a backslash, then the filename, like this:
imagesbmp
gamefilesbmp
Relative Path
Relative paths to files that exist in folders at the same level in the directory tree, (or in a higher level), use
the ".." designation to indicate "go up one level from the DefaultDir$". Filenames are usually designated by
including a dot and a file extension that specifies the type of file. Filenames ending in ".txt" are text files, (for
instance), while filenames ending in ".bmp" are bitmaps. Folders do not typically have extensions. The
names below with extensions indicate files, while the names without extensions indicate folders. Here are
some examples of relative paths:
Caveat
It is very unlikely that other users of a program will have the same directory structure on their computers as
the programmer who writes the code. For this reason, it is best to use one of the other path naming options
listed above that does not depend upon all users having the same directory structure on their computers.
LOADBMP
OPEN
PLAYWAVE
BMPBUTTON
Mathematics
Previous Top Next
See also Numeric Variables , Mathematical Operations , Trigonometry , Numbers and Strings
Scientific Notation
Liberty BASIC supports scientific notation in code:
print 1.2345e-4
Arithmetic
Arithmetic operators are as follows:
+ addition
- subtractiong
* multiplication
/ division
^ power
Examples:
print 2 + 3 'addition
print 6 - 2 'subtraction
print 4 * 7 'multiplication
print 9 / 3 'division
Order
Expressions are evaluated in this order:
() expressions within parentheses are evaluated first
See also:
SIN
COS
TAN
ASN
ACS
ATN
ABS
EXP
LOG
INT
RND
SQR
VAL
STR$
USING
Numeric variables
Previous Top Next
In Just BASIC, numeric variables hold either a double-precision floating point value, or an integer. A
floating point value will be converted to an integer if its fractional part is zero when it is assigned to a
UNREGISTERED VERSION
variable. Integers OF CHM
in Just BASIC TO
can be PDF CONVERTER By THETA-SOFTWARE
huge.
Only nine digits are displayed when floating point values are printed, unless the USING() function is used to
force the display of the number of digits desired after the decimal point.
When first referenced, numeric variables equal 0. Values are assigned to variables with the equals sign
UNREGISTERED
"=". VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
myVar = 42
In the following code, the variable "totalNum" is 0 to begin, so adding 3 to it gives it a value of 3. Adding 8
to it in the next line gives it a value of 11.
totalNum = totalNum + 3
'totalNum now contains the value 3
totalNum = totalNum + 8
'totalNum now contains the value 11
NOTE: Just BASIC does not support the CONST keyword that is common in some other forms of BASIC
such as QBASIC.
Negative numbers.
Just BASIC does not support changing the sign of a variable directly by preceding it with a negative sign "-
". Instead the variable must be multiplied by -1
GLOBAL
In general, variables used in the main program code are not visible inside functions and subroutines.
Variables inside functions and subroutines are not visible in the main program. Just BASIC introduces the
GLOBAL statement to create global variables. Variables declared as GLOBAL can be seen everywhere in
a program. See GLOBAL . The special system variables like WindowWidth, WindowHeight, etc. now have
true global status. GLOBALS are specified and used like this:
ABS( n )
Description:
This function returns | n | (the absolute value of n). "n" can be a number or any numeric expression.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
SQR(n)
Description:
This function returns the square root of the number or numeric expressioin n.
Usage:
EXP( n )
Description:
This function returns e ^ n, with e being 2.7182818 . . .
Usage:
LOG( n )
Description:
This function returns the natural log of n.
Usage:
INT( n )
Description:
This function removes the fractional part of number, which is the part of the number after the decimal point,
leaving only the whole number part behind.
Usage:
[retry]
input "Enter an integer number>"; i
if i<>int(i) then
print i; " isn't an integer! Re-enter."
goto [retry]
end if
RND(number)
Description:
This function returns a random number between 0 and 1. The number parameter is usually set to 1, but the
value is unimportant because it is not actually used by the functoin. The function will always return an
arbitrary number between 0 and 1.
Usage:
RANDOMIZE n
Description:
This function seeds the random number generator in a predictable way. The seed numbers must be greater
than 0 and less than 1. Numbers such as 0.01 and 0.95 are used with RANDOMIZE.
Usage:
Tip: There are 2 * pi radians in a full circle of 360 degrees. A formula to convert degrees to radians is:
radians = degrees divided by 57.29577951 Here are some helpful functions to convert degrees to
UNREGISTERED VERSION
radians, radians OFand
to degrees CHM TO PDF
to calculate PI.CONVERTER By THETA-SOFTWARE
function pi()
pi = asn(1) * 2
end function
UNREGISTERED
function VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
rad2deg(num)
rad2deg = 90 / asn(1) * num
end function
function deg2rad(num)
deg2rad = asn(1) / 90 * num
end function
ACS( n )
Description:
This function returns the arc cosine of the number or numeric expression n. The return value is
expressed in radians.
Usage:
ASN( n )
Description:
This function returns the arc sine of the number or numeric expression n. The return value is expressed
in radians.
Usage:
ATN( n )
Description:
This function returns the arc tangent of the number or numeric expression n. The return value is
expressed in radians.
Usage:
COS( n )
Description:
This function returns the cosine of the angle n. The angle n should be expressed in radians.
Usage:
for c = 1 to 45
print "The cosine of "; c; " is "; cos(c)
next c
SIN( n )
Description:
This function returns the sine of the angle n. The angle n should be expressed in radians.
Usage:
for t = 1 to 45
print "The sine of "; t; " is "; sin(t)
next t
TAN( n )
This function returns the tangent of the angle n. The angle n should be expressed in radians
Usage:
for t = 1 to 45
print "The tangent of "; t; " is "; tan(t)
next t
Numbers and Strings
Previous Top Next
Just BASIC has several functions that convert numeric values and strings.
VAL(stringExpression)
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function returns a numeric value for stringExpression if stringExpression represents a valid numeric
value or if it begins with a valid numeric value. If not, then zero is returned.
Usage:
UNREGISTERED
print 2 VERSION OF CHM TO PDF
* val("3.14") CONVERTER6.28
Produces: By THETA-SOFTWARE
STR$( numericExpression )
Description:
This function returns a string expressing the result of numericExpression.
Usage:
age = 23
age$ = str$(age)
price = 2.99
price$ = str$(price)
totalApples = 37
print "Total number of apples is " + str$(totalApples)
USING(templateString, numericExpression)
Description:
This function formats numericExpression as a string using templateString. The rules for the format are
similar to those in Microsoft BASIC's PRINT USING statement, but since using( ) is a function, it can be
used as part of a larger BASIC expression instead of immediate output only. The template string consists of
the character "#" to indicate placement for numerals, and a single dot "." to indicate placement for the
decimal point. The template string must be contained within double quotation marks. If there are more digits
contained in a number than allowed for by the template string, the digits will be truncated to match the
template.
template$ = "######.##"
amount$ = using(template$, 1234.56)
Using() may be used in conjunction with 'print'. The following two examples produce the same result:
The using() function for Just BASIC rounds its output like PRINT USING does in other BASICs.
Usage:
Just BASIC provides several ways to retrieve date and time information. Date$() and Time$() are functions
that return values that can be used in mathematical operations. Some forms return a string, while others
return a number. See also Date$ and Time$
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Date$()
'This form of date$() produces this format
print date$() ' Nov 30, 1999 STRING
UNREGISTERED VERSION OF CHM
print date$("mm/dd/yyyy") TO11/30/1999
' PDF CONVERTER By THETA-SOFTWARE
STRING
print date$("mm/dd/yy") ' 11/30/99 STRING
print date$("yyyy/mm/dd") ' 1999/11/30 STRING for sorting
print date$("days") ' 36127 NUMBER days since Jan 1, 1901
print date$("4/1/2002") ' 36980 NUMBER days since Jan 1, 1901 for
given date
print date$(36980) ' 04/01/2002 STRING mm/dd/yyyy string returned
' when given days since Jan 1, 1901
Date$() Math
Here is a small program that demonstrates one way that Date$() can be used with math operators.
today = date$("days")
target = date$("1/1/2004") 'subsititute value for next year
print "Days until the new year: ";
print target - today
Time$()
'this form of time$() produces this format
print time$() 'time now as string "16:21:44"
print time$("seconds") 'seconds since midnight as number 32314
print time$("milliseconds") 'milliseconds since midnight as number 33221342
print time$("ms") 'milliseconds since midnight as number 33221342
Time$() Math
Here is a small program that demonstrates one way that Time$() can be used with math operators.
This section of the help system explains the use and manipulation of text as literal strings of characters or as
string variables. It also details commands for text windows and text editors.
UNREGISTERED
String LiteralsVERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
and Variables
Manipulating Characters
Text Mode Display in the Mainwin
Text Commands
See also:
UNREGISTERED VERSION
Sending text to the Printer OF
with CHM TO PDF CONVERTER By THETA-SOFTWARE
LPRINT
String Literals and Variables
Previous Top Next
Literal Strings
A string literal always starts with a quotation mark and always ends with a quotation mark. No quotation
marks are allowed in between the starting and ending quotation marks. Here is an example that prints a
string literal in the mainwin.
Hello World
String Variables
There are special variables for holding words and other non-numeric character combinations. These
variables are called string variables (they hold strings of characters*).
*Characters are:
Digits 0123456789 ;
Any other special symbols like: , . < > / ? ; : ' " [ ] ` ~ ! @ # $ % ^ & * ( ) + - | etc . . .
String variable names must end with a $ (dollar sign). Text is assigned to a string variable using the equals
sign ( = ). This example assigns "Hello World" to the string variable hello$ and then prints it in the mainwin.
Hello World
NOTE - A string can have zero characters. Such a string is often called an empty string. In BASIC, an
empty string can be expressed in a string literal as two quotation marks without any characters between
them. For example (noCharactersHere$ is the name of our string variable):
Concatenation
Two strings of text can be joined together (concatenated), either as variables, literals or both. This is
accomplished by use of the plus sign ( + ).
varOne$ = "Hello"
varTwo$ = "World"
varThree$ = varOne$ + " " + varTwo$
print varThree$
Hello World
It is also possible to use the semi-colon ( ; ) to add, or concatenate strings.
varOne$ = "Hello"
varTwo$ = "World"
varThree$ = varOne$ ; " " ; varTwo$
print varThree$
UNREGISTERED VERSION
NON-PRINTING OF CHM TO PDF CONVERTER By THETA-SOFTWARE
CHARACTERS
Some characters do not display on the screen, but instead they format the text output. A combination of
carriage return and line feed causes text printed after it to display on the next line down. These non-
keyboard characters can be accessed with the CHR$(n) function. "n" is be the ascii value of the desired
character. In the case of a CRLF as described here, the character for "carriage return" is chr$(13). The
character for "line feed" is chr$(10). The following code inserts a carriage return, forcing the text to print on
UNREGISTERED
two lines. VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Produces:
Hello
World
Produces:
"Hello World"
GLOBAL
In general, variables used in the main program code are not visible inside functions and subroutines.
Variables inside functions and subroutines are not visible in the main program. Variables declared as
GLOBAL can be seen everywhere in a program. See GLOBAL . The special system variables like
WindowWidth, WindowHeight, etc. now have true global status. GLOBALS are specified and used like this:
CHR$( n )
Description:
This function returns a one character long string, consisting of the character represented on the ASCII table
by the value n (0 - 255).
Usage:
print chr$(77)
print chr$(34)
print chr$(155)
Produces:
M
"
Usage:
If string2 is not found in string1, or if string2 is not found after starting, then INSTR( ) will return 0.
and so does:
LEN( string )
Description:
This function returns the length in characters of string, which can be any valid string expression.
Usage:
LEFT$(string, number)
Description:
UNREGISTERED VERSION
This function returns OF CHM
from string TO PDF
the specified CONVERTER
number of charactersBy THETA-SOFTWARE
starting from the left. If string is "hello
there", and number is 5, then "hello" is the result.
Usage:
[retry]
UNREGISTERED VERSION
input "Please OFaCHM
enter TO PDF CONVERTER
sentence>"; sentence$ By THETA-SOFTWARE
if sentence$ = "" then [retry]
for i = 1 to len(sentence$)
print left$(sentence$, i)
next i
Produces:
Note: If number is zero or less, then "" (an empty string) will be returned. If number is greater than or equal
to the number of characters in string, then string will be returned.
RIGHT$(string, number)
Description:
This function returns a sequence of characters from the right hand side of string using number to determine
how many characters to return. If number is 0, then "" (an empty string) is returned. If number is greater
than or equal to the number of characters in string, then string will itself be returned.
Usage:
Produces:
right handed
And:
Produces:
hello world
Usage:
Produces:
Earth
And:
string$ = "The quick brown fox jumped over the lazy dog"
for i = 1 to len(string$) step 5
print mid$(string$, i, 5)
next i
Produces:
The_q
uick_
brown
_fox_
jumpe_
d_ove
r_the
_lazy
_dog
LOWER$( string )
Description:
This function returns a copy of the contents of string, but with all letters converted to lowercase.
Usage:
Produces:
Usage:
UNREGISTERED
Produces: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
TRIM$( string )
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function removes any spaces from the start and end of string. This can be useful for cleaning up data
entry among other things.
Usage:
Produces: 9
SPACE$( n )
Description:
This function will a return a string of n space characters (ASCII 32). It is useful when producing formatted
output to a file or printer.
Usage:
for x = 1 to 10
print space$(x); "*"
next x
Produces:
*
*
*
*
*
*
*
*
*
*
Text mode display
Previous Top Next
By default, each Just BASIC program has a main window, called the "mainwin." This is a simple text
display with scrollbars.
Displaying Text
The standard PRINT command causes text to be displayed in the mainwin.
produces
Hello World
After the expressions are displayed, the cursor (that blinking vertical bar | ) will move down to the next line,
and the next time information is sent to the window, it will be placed on the next line down. To prevent the
cursor from moving immediately to the next line, add an additional semicolon to the end of the list of
expressions. This prevents the cursor from being moved down a line when the expressions are displayed.
The next time data is displayed, it will be added onto the end of the line of data displayed previously.
Usage: Produces:
age = 23
print "Ed is "; age; " years old" Ed is 23 years old
Most versions of Microsoft BASIC implement INPUT to automatically place a question mark on the display in
front of the cursor when the user is prompted for information:
produces:
Please enter the upper limit ? |
UNREGISTERED
produces: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
and:
produces simply:
?|
In the simple form input limit, the question mark is inserted automatically, but if a prompt is specified, as in
the above example, only the contents of the prompt are displayed, and nothing more. If it is necessary to
obtain input without a prompt and without a question mark, then the following will achieve the desired effect:
Additionally, in most Microsoft BASICs, if INPUT expects a numeric value and a non numeric or string value
is entered, the user will be faced with a comment (something like 'Redo From Start'), and be expected to
reenter. Just BASIC does not automatically do this, but converts the entry to a zero value and sets the
variable accordingly.
Mainwin Size
It is possible to set the number of columns and rows in the mainwindow using the MAINWIN statement.
Here is how to set 40 columns and 20 rows:
Locating Text
Using LOCATE in the mainwin causes text to be printed at the x, y location specified. These coordinates
refer to the column and row of text, not to screen pixels. This command functions in the same way as the
QBasic LOCATE command and is used to position text on the mainwin. Here is a short demo:
'plot a wave
for x = 1 to 50
i = i + 0.15
locate x, 12 + int(cos(i)*10)
print "*";
next x
Print TAB(n)
Just BASIC has the ability to use the TAB function for formatting output. "n" is the character location where
the next output will be printed. "tab(7)" causes the next output to print beginning at column (character) 7,
while "tab(21)" causes the next output to print beginning at column 21.
The commands in this topic work with the text window and texteditor control. Anything printed to a text
window is displayed exactly as sent. To distinguish commands sent to a text window from text that is to be
UNREGISTERED
diplayed in theVERSION
window, theOF CHM TO
! character PDF
should be CONVERTER
the first characterBy THETA-SOFTWARE
in the string. It is no longer necessary to
add a semicolon to the end of a printed command line to suppress a carriage return. The semicolon at the
end of a printed command is now optional. When printing text, rather than commands, a carriage return is
added to the text with each print statement, unless the statement ends with a semicolon.
Variables must be places outside the quotation marks, with blank spaces preserved:
lineNum=3
print #handle, "!line ";lineNum;" string$"
See also: Understanding Syntax - how to use literals and variables in commands.
For example:
'read line 1
print #1, "!line 1"
input #1, string$
print "The first line is:"
print string$
input "Press 'Return'"; r$
nomainwin
open "Example" for text as #1
print #1, "!trapclose [quit]"
'blank line:
print #1, ""
#1 "Done!"
wait
[quit]
close #1 : end
Note: Most of the commands listed below work with windows of type "text" and also with the "texteditor"
control except where noted.
This command has two forms as described above. The first form causes the contents of the text window to
be replaced with the contents of varname$, and the second form causes the contents of the text window to
be replaced with the contents of the stream referenced by #handle. This second form is useful for reading
large text files quickly into the window.
This command returns the entire text of the window. After this command is issued, the entire text is
contained in the variable string$.
UNREGISTERED VERSION
This command causes the OF CHMselected
currently TO PDFtextCONVERTER Bytext
to be cut out of the THETA-SOFTWARE
window and copied to the
WINDOWS clipboard.
This command sets the font of the text window to the specified name and size. If an exact match cannot be
found, then Just BASIC will try to match as closely as possible, with size taking precedence over name in the
match. Note that a font with more than one word in its name is specified by joining each word with an
underscore _ character. For example, the font Times New Roman becomes Times_New_Roman, and the
font Courier New becomes Courier_New.
Example:
Returns the text at line n. In the code above, n is standing in for a literal number. If n is less than 1 or
greater than the number of lines the text window contains, then "" (an empty string) is returned. After this
command is issued, the line's text is contained in the variable string$.
This sample code retrieves the contents of line number 7 and places them into a variable called string$:
print #textwindow, "!line 7 string$"
This command returns the number of lines in the text window, placing the value into the variable countVar.
This command returns a string (either "true" or "false") that indicates whether any data in the text window
has been modified. The variable answer$ holds this returned string. This is useful for checking to see
whether to save the contents of the window before closing it.
This command forces the origin of the window to be row and column. This means that the row and column
specified will appear in the upper left corner of the texteditor or text window. Row and column must be literal
numbers. To use variables for these values, place them outside the quotation marks, preserving the blank
spaces, like this:
This causes the text in the WINDOWS clipboard (if there is any) to be pasted into the text window at the
current cursor position.
This command returns the highlighted text from the window. The result will be contained in the variable
selected$.
This causes Windows to give input focus to this control. This means that, if some other control in the same
window was highlighted and active, this control now becomes the highlighted and active control, receiving
keyboard input.
This command tells Just BASIC to continue execution of the program at branchLabel if the user double
clicks on the system menu box or pulls down the system menu and selects "close."
Graphics
Previous Top Next
Just BASIC supports drawing operations. There are two kinds of controls that accept drawing commands;
UNREGISTERED VERSION
one is a kind of OFtheCHM
window, and other TO
is a PDF
controlCONVERTER By THETA-SOFTWARE
called a graphicbox. They both support the same
drawing operations. Here is an example of a graphics window:
And here's the same drawing operation in a graphicbox which has been inserted into a window.
The graphics operations are performed by a pen. The pen can be up or down. If the pen is up, the
drawing operations will not appear. The pen moves, but does not draw. The pen defaults to the up
position.
Turtle Graphics
Turtle graphics are drawn by a pen that moves about the screen from one location to another, drawing
if is in the DOWN position. Turtle graphics are good for drawing graphics and iterative objects.
Drawn Objects
Objects such as boxes, lines and circles may be drawn, and they may be either filled with an opaque
color, or they may be drawn as an outline only.
Drawn Text
Graphics commands include the ability to place text on the graphics control at the location desired.
FLUSH
Drawing commands can be made to persist, or "stick" when the FLUSH command is used:
graphicbox #w.g, 5, 5, 250, 250
open "I'm a window!" for window as #w
print #w.g, "home ; down"
print #w.g, "fill green"
print #w.g, "circle 100"
print #w.g, "flush"
wait
CLS
The simplest way to delete drawing commands is to issue the CLS command before new graphics drawing
commands are issued:
When this method is used, the screen goes blank for an instant before new drawn items are displayed,
causing a flickering or blinking effect.
The number of the currently active segment is retrieved with the segment command:
This gets the segment number of the current segment and places it into the variable drawSegment.
Subtracting 1 from the current segment number will reference the last segment that has been FLUSHed. It
can then be deleted with the DELSEGMENT command, as in this example:
DISCARD
The DISCARD command will remove any unflushed drawing commands. An example is as follows:
'demonstrate discard
open "Sine wave" for graphics as #sine
print #sine, "home ; down ; posxy x y"
print #sine, "place 0 "; y
width = x * 2
for x = 0 to width
print #sine, "goto "; x; " "; y + (y * sin(x/40))
next x
print #sine, "discard" 'no redraw info kept
wait
end
The program above draws a sine wave, discarding drawn graphics. If the graphics window is maximized
after the drawing is complete, it is possible to see that the graphics are not redrawn. This is similar to the
effect achieved when FLUSH is not used, but in fact it throws away the graphics instructions so memory
does not get filled up.
When a window is closed, all graphics drawing operations are deleted from memory.
A graphics window or graphicbox is able to read mouse and keyboard input. Here is the world's smallest
painting program!
The mouse location within the graphics area can be retrieved from the MouseX and MouseY variables.
The Inkey$ variable holds the character of the key pressed. In order to capture keyboard input the
graphics device must have focus. Sometimes it is necessary to force the input focus using the setfocus
command:
[draw]
#draw, "set "; MouseX; " "; MouseY
wait
UNREGISTERED VERSION
Keyboard OF CHM
input example withTO PDF CONVERTER
subroutine event handler By THETA-SOFTWARE
Here's a simple program that monitors user keypresses. When the characterInput event happens the
keyCheck subroutine gets called, and the graphicbox handle and Inkey$ values get passed in.
'a simple keycheck program
[keyCheck]
#draw, ";Inkey$
wait
See also: graphics commands , Inkey$ , and Using Virtual Key Contants with Inkey$ for more details.
Graphics Commands
Previous Top Next
See also: Understanding Syntax - how to use literals and variables in commands.
Most of these commands work only with windows of type graphics and with the graphicbox control.
It should be noted that graphics windows and graphicboxes are intended for drawing graphics. It is not
advisable to place controls within them, since some controls do not work properly when placed in
graphicboxes or graphics windows. If there is a need for text display within a graphicbox or graphics window,
use the graphics text capabilities rather than a statictext control.
IMPORTANT NOTE: In order to draw, you must make sure that the drawing pen is
down, and not up. See below for more information.
Because graphics can involve many detailed drawing operations, Just BASIC allows mutliple commands to
be listed in a single command statement if they are separated by semicolons. The following example shows
several graphics commands, each on its own line:
The same commands can be issued on a single line, and will execute slightly faster:
If text is displayed using graphics commands, a semicolon may not be used after the command to display
the text. When graphictext is designated by the use of the ( ) or ( | ) character, any semicolons that follow in
the same line are considered to be part of the text string to display.
Important: When drawing to a graphics window or graphic box, the operations that are performed are stored
in memory by Just BASIC so that lightning fast redraws can be performed. This storage function uses
memory. If an application continually draws raphics, the system will eventually run out of memory and even
potentially crash the computer. To prevent this, the application should only store those drawing operations
which are needed to display its current state. The cls, delsegment, discard and flush commands help to
manage graphics memory. See also: Graphics
Just BASIC supports sprites in graphic windows and in graphicbox controls. Only one graphicbox or
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
graphics window in a program may use sprites. To learn more about using sprites, see Sprites .
x=12 : y = 57
print #handle, "box ";x;" ";y
GRAPHICBOX COMMANDS
The following commands are sent to a graphicbox. When a graphicbox is disabled, it can no longer capture
keyboard and mouse events.
This causes the edges of the control to maintain their distance from the edges of the overall window. If the
user resizes the window, the graphicbox control also resizes.
black, blue, brown, buttonface, cyan, darkblue, darkcyan, darkgray, darkgreen, darkpink, darkred, green,
lightgray, palegray, pink, red, white, yellow
Palegray and Lightgray are different names for the same color. Buttonface is the default background color
currently set on a user's system, so it will vary according to the desktop color scheme. Here is a graphical
representation of the named colors:
Example:
UNREGISTERED VERSION
print #handle, "piefilled wOF CHM angle2"
h angle1 TO PDF CONVERTER By THETA-SOFTWARE
This command draws a pie slice inside an ellipse of width w and height h. The pie slice will begin at angle1,
and sweep clockwise angle2 degrees if angle2 is positive, or sweep counter-clockwise angle2 degrees if
angle2 is negative. The pie slice is fillled with the color specified using the BACKCOLOR command.
UNREGISTERED VERSION
print #handle, "place X Y"OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command positions the pen at X Y. No graphics will be drawn, even if the pen is DOWN.
_R2_BLACK
_R2_WHITE
_R2_NOP
_R2_NOT
_R2_COPYPEN <- the default LB drawing rule
_R2_NOTCOPYPEN
_R2_MERGEPENNOT
_R2_MASKPENNOT
_R2_MERGENOTPEN
_R2_MASKNOTPEN
_R2_MERGEPEN
_R2_NOTMERGEPEN
_R2_MASKPEN
_R2_NOTMASKPEN
_R2_XORPEN
_R2_NOTXORPEN <- the xor LB drawing rule
Each additional in the text will cause a carriage return and line feed. For example, print #handle, "" will
cause text1 to be printed at the pen position, and then text2 will be displayed directly under text1.
This command works like print #handle, "" above, but uses the | character instead of the character, which
allows display of the character a ( ).
UNREGISTERED VERSION
print #handle, "up" OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command lifts up the pen. All GO or GOTO commands will now only move the pen to its new position
without drawing. Any other drawing commands will simply be ignored until the pen is put back down.
The eventHandler can be a valid branch label or the name of a subroutine. See also: Controls and Events
Sending print #handle, "when leftButtonDown [startDraw]" to a graphicbox or graphics window will tell that
window to force a goto [startDraw] if the mouse is inside that window when the user presses the left mouse
button. Sending "when leftButtonDown startDraw" to a graphics window or graphicbox tells the window to
call the subroutine startDraw if the mouse is inside that window when the user presses the left mouse button.
The graphicbox handle, MouseX and MouseY variables are passed into the designated subroutine. If
keyboard input is trapped, the graphicbox handle and the value of the key pressed are passed into the
designated subroutine. See Reading Mouse Events and Keystrokes .
Whenever a mouse event is trapped, Just BASIC places the x and y position of the mouse in the variables
MouseX, and MouseY. The values represent the number of pixels in x and y the mouse was from the upper
left corner of the graphic window display pane.
Whenever a keyboard event is trapped, Just BASIC places the value of the key(s) pressed into the special
variable, Inkey$. See Using Inkey$ .
If the expression print #handle, "when event" is used with no branch label designation, then trapping for that
event is discontinued. It can however be reinstated at any time. Example of turning off the leftButtonDown
event handler:
print #handle, "when leftButtonDown"
WARNING: using graphicboxes in dialog-type windows is fine, but they do not properly accept the input
focus for keyboard input. If a program needs graphicboxes that trap keyboard events, then a window of type
"window" must be used.
See also: Graphics , Inkey$ , Using Virtual Key Contants with Inkey$ ., Using Inkey$ , Reading Mouse
Events and Keystrokes
Sprite Table of Contents
Previous Top Next
Sprite Commands
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
What is a Sprite?
How Do Sprites Work?
Start with the Background
Designate Sprites
Sprite Properties
Drawing and Collision Detection
UNREGISTERED
Flushing SpriteVERSION
Graphics OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Pauses and Timing
Add a Mask
Step by Step
Simple Demo Program
ADDSPRITE
print #w.g, "addsprite SpriteName BmpName";
This adds a sprite with name SpriteName from loaded bitmap called BmpName.
print #w.g, "addsprite SpriteName bmp1 bmp2 bmp3 ... bmpLast";
This adds a sprite with name SpriteName from loaded bitmaps - may include any number of bitmaps.
BACKGROUND
print #w.g, "background BmpName";
This sets the background for sprites to be the loaded bitmap called BmpName.
CYCLESPRITE
print #w.g, "cyclesprite SpriteName 1"
print #w.g, "cyclesprite SpriteName -1"
print #w.g, "cyclesprite SpriteName 1 once"
This causes a sprite to cycle through its image list automatically. Using "1" will cause the list to cycle
forward. Using "-1" will cause the list to cycle backwards. Using the optional "once" parameter will cause
the sprite to cycle through its image list only one time, other wise it cycles continuously.
DRAWSPRITES
print #w.g, "drawsprites";
This causes all visible sprites to be drawn on the background and it updates the display.
REMOVESPRITE
print #w.g, "removesprite SpriteName";
This causes the named sprite to be removed from the collection of sprites.
SPRITECOLLIDES
print #w.g, "spritecollides SpriteName";
input #w.g, list$
OR
print #w.g, "spritecollides SpriteName list$";
This causes a list of all sprites that collided with the sprite named SpriteName to be contained in the variable
called "list$".
SPRITEIMAGE
print #w.g, "spriteimage SpriteName BmpNameX";
This causes the sprite called SpriteName to be shown as the image from its image list called BmpNameX.
SPRITEMOVEXY
print #w.g, "spritemovexy SpriteName 5 5";
OR
x=5:y=5
print #w.g, "spritemovxy SpriteName ";x;" ";y
This causes a sprite called SpriteName to move x pixels in the x direction, and y pixels in the y direction
each time a DRAWSPRITES command is issued to update the display.
SPRITEORIENT
print #w.g, "spriteorient SpriteName normal";
print #w.g, "spriteorient SpriteName flip";
print #w.g, "spriteorient SpriteName mirror";
print #w.g, "spriteorient SpriteName rotate180";
This causes the sprite called SpriteName to be oriented in one of the four directions: normal, flip, mirror,
rotate180.
SPRITESCALE
print #w.g, "spritescale SpriteName 150";
OR
UNREGISTERED
percent=150 VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
print #w.g, "spritescale SpriteName ";percent
This causes the sprite called SpriteName to be scaled by the percentage designated in both width and
height.
SPRITEVISIBLE
UNREGISTERED VERSION
print #w.g, OF CHMSpriteName
"spritevisible TO PDF CONVERTER
on"; By THETA-SOFTWARE
print #w.g, "spritevisible SpriteName off";
This causes the sprite called SpriteName to be visible if "on" is used, or to be invisible if "off" is designated.
SPRITEXY
print #w.g, "spritexy SpriteName 100 137";
OR
x=100:y=137
print #w.g, "spritexy SpriteName ";x;" ";y
This causes the sprite called SpriteName to be drawn at position x, y the next time the display is updated
with the DRAWSPRITES command.
SPRITEXY?
print #w.g, "spritexy? SpriteName"
input #w.g, x, y
OR
print #2.g "spritexy? SpriteName x y"
This obtains the coordinates of the sprite called SpriteName and places them into the variables x and y.
What is a Sprite?
Previous Top Next
A program might need to put a picture of a hopping frog onto this background.
It is possible to make it look like the frog is part of the picture by using sprites. When done with sprites, the
picture looks like this:
How Do Sprites Work?
Previous Top Next
As was explained in the previous section, bitmaps are rectangular. Realistic graphics require a way to place
the image from a bitmap onto a background without including the image's own background. If this were to
UNREGISTERED VERSION
be done with an OF on
actual picture CHM TOofPDF
a piece CONVERTER
paper, desired parts ofBy
the THETA-SOFTWARE
image could be cut out, and the
remaining parts of the picture could be discarded. This cutout could then be pasted onto the background.
This can be done with bitmaps.
MASKS
Images are added to a background in layers. There are two versions of the image, which are called a mask
UNREGISTERED
and a sprite. VERSION
The mask is putOFonCHM
first. TO PDFhas
A mask CONVERTER By THETA-SOFTWARE
a white background. The shape of the image is the
actual mask, and it is all black. A mask is a black and white image. Here is a mask for the frog image:
SPRITES
The sprite is the image as it will appear, with a completely black background:
It is possible to add a mask to the sprite image using Paint, PaintBrush, or any other painting utility, but the
easiest way to add the mask is to use the Just BASIC program provided as part of this help file. Add a mask
here .
LAYERING
Sprites are displayed by combining the pixels of the background with the pixels of the mask and sprite
bitmaps, using bitwise operations. The programmer does not need to deal with these operations, because
they are done by Just BASIC. A Just BASIC sprite bitmap contains the mask above the sprite. The mask is
placed on the background bitmap in memory. It is not displayed on the screen in this form:
The mask is now in place. The next layer adds the sprite, and results in this picture, which is displayed on
the screen when a DRAWSPRITES command is issued:
IMPORTANT!
To avoid flickering, sprite animation is done invisibly, in memory. When an entire frame of animation is built,
it is then transferred to the screen. IT WILL COVER ANY PREVIOUS GRAPHICS IN THE GRAPHICBOX
OR ON THE GRAPHICWINDOW. See the section on Drawing and Collision Detectio n for information about
adding graphics to a window with Just BASIC graphic commands during sprite animation.
WindowHeight = 320
WindowWidth = 400
UNREGISTERED VERSION
graphicbox #w.g,OF
0,CHM TO PDF
0, 400, 300 CONVERTER By THETA-SOFTWARE
open "sprite test" for window_nf as #w
A window that contains sprites must include a graphicbox, or it must be a graphics window. Only one
graphicbox or graphics window in a program may use sprites.
UNREGISTERED VERSION
BACKGROUND OF CHM
FROM LOADED TO PDF CONVERTER By THETA-SOFTWARE
BITMAP
There are several ways to designate a background image. One way is to use a loaded bitmap as the
background. The bitmap must first be loaded with the LOADBMP command:
The BACKGROUND command sets the bitmap called "landscape" to be the background:
Note that simply setting the background bitmap does not cause the background image to display on the
screen. See the section on Drawing and Collision Detection to find out about updating the display.
Here is an example. The width of the following bitmap is greater than the width of the graphicbox, so it
remains unchanged. The height of the bitmap is less than the height of the graphicbox, so it is stretched to
fit.
DEFAULT BACKGROUND
If no BACKGROUND command is issued, a plain white background will be used.
To set a new bitmap called "mountains" as the background, just use the BACKGROUND command after
loading the bitmap:
IMPORTANT!
The background will not appear in the graphicbox or graphics window until the DRAWSPRITES command is
given. This command updates the display. Even if there are no sprites in use, or if no sprites are visible, the
DRAWSPRITES command must be issued to display the background onscreen. Whenever the
BACKGROUND command is issued, it must be followed by a DRAWSPRITES command to cause it to show
on the screen.
Designate Sprites
Previous Top Next
A sprite bitmap must include a mask above and a sprite below, like this:
UNREGISTERED VERSION
The bitmap must be loadedOF
withCHM TO PDFcommand:
the LOADBMP CONVERTER By THETA-SOFTWARE
NAME
The command to add the sprite to the program is ADDSPRITE. It designates the NAME to give this sprite,
and then the name for the sprite bitmap that was given with LOADBMP. These names can be the same, as
in this example:
Or, the designated sprite NAME can be different from the LOADBMP name. Below, the bitmap is named
"smiley" when it is loaded, and it is given the spritename, "guy".
The spritename is used to refer to this sprite when setting its properties, or issuing commands to it. The
image for a designated sprite can be changed by issuing the ADDSPRITE command again:
None of the properties of the "guy" sprite change when the image is changed.
VISIBILITY
All added sprites will be drawn in each frame of animation. The SPRITEVISIBLE command is used to
specify whether a sprite is visible or not.
The individual bitmaps for the sprite images must be loaded with LOADBMP. The bitmaps for the frog look
like this:
Now the sprite with the NAME of "frog" contains three individual frog images. To see how to make Just
BASIC cycle through these images when drawing the frog sprite, see the section on Sprite Propertie s.
Bitmaps can be used multiple times within one sprite designation. Note that "frog2" is used twice here:
The individual images of a sprite can be cycled automatically by issuing a CYCLE command, which is
discussed along with other sprite properties in Sprite Properties .
IMPORTANT!
To avoid flickering, sprite animation is done invisibly, in memory. A frame of animation is built entirely off-
screen. A frame of animation is displayed on the screen only when the command DRAWSPRITES is called.
For each frame of animation, perform all functions to set the background image, and to set or change a
sprite's properties, then call the DRAWSPRITES command. Learn about updating the display in Drawing
adn Collision Detection .
Sprite Properties
Previous Top Next
Sprite properties include NAME, VISIBLE, SCALE, ORIENTATION, CYCLE, LOCATION, MOTION,
TRAVEL, Z ORDER.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
The properties VISIBLE and NAME are discussed in Designating Sprites . Sprites have several other
properties that can be set by the programmer.
CYCLE
Just BASIC will automatically cycle through the image list for a sprite, if given the CYCLESPRITE command.
UNREGISTERED
The commandVERSION OF
also requires theCHM TO
sprite's NAMEPDFandCONVERTER By THETA-SOFTWARE
a value for the frame count. A value of "1" will cause the
sprite to cycle through all images in its list from first listed to last listed. A value of "-1" will cause the sprite to
cycle through all of its images in the reverse order from which they were listed. A value equal to one of the
images in the list will cause the sprite to cycle to that image. To cycle forward through all images:
or backwards:
For the example with three frogs, Just BASIC will cycle through these three images when drawing frames of
animation:
CYCLE ONCE
Adding ONCE to the CYCLESPRITE command causes the sprite to cycle through its frames of animation,
either forward, or backward, only one time, and then stop at the last (or first) frame. After the single cycle
through frames, the sprite will appear as the last (or first) frame until a different cycle command is issued.
This is useful for animations such as explosions.
SCALE
A sprite may be scaled to a percentage of its original width and height with the SPRITESCALE command. A
percentage of 200 will cause the sprite to appear twice the original width and height, while a percentage of
50 will cause it to be half as large as the width and height of the loaded bitmap. To change the size of a
sprite to be one and one-half times the width and height of the loaded bitmap:
print #w.g, "spritescale smiley 150";
ORIENTATION
By default, sprites are shown just as they appear in the loaded bitmap. It is easy to cause them to appear as
a mirror image of the loaded bitmap, or flipped, or rotated 180 degrees. It is not possible to rotate 90 or 270
degrees, so these rotations will require separate sprites/bitmaps. Sprites can have alterations in both scale
and orientation at one time.
Just BASIC will automatically move a sprite each time a new frame is drawn, if the SPRITEMOVEXY
command is issued. The following command moves the sprite named "smiley" 5 pixels in the x direction and
2 pixels in the y direction each time a new animation frame is drawn.
A sprite is stopped from moving automatically by the SPRITEMOVEXY command and values of 0 for the x
and y movement:
IMPORTANT!
To avoid flickering, sprite animation is done invisibly, in memory. A frame of animation is built entirely off-
screen. A frame of animation is displayed on the screen only when the command DRAWSPRITES is called.
For each frame of animation, perform all functions to set the background image, and to set or change a
sprite's properties, then call the DRAWSPRITES command. Now, we're ready to start drawing the animated
sprites! See the section on Drawing and Collision Detection !
Drawing and Collision Detection
Previous Top Next
UNREGISTERED VERSION
The DRAWSPRITES OF CHM
command TOthePDF
updates CONVERTER
display, By THETA-SOFTWARE
causing all VISIBLE sprites to be drawn at their current
LOCATIONS, moving them if the SPRITEMOVEXY command has been issued. They will display in their
current SCALE and ORIENTATION. This command must be given each time it is necessary to draw
another frame of animation. Sprite attributes may be changed in between the DRAWSPRITES commands,
including their location, orientation, and scale. If the background image is to be moved, the
BACKGROUNDXY command must be issued before the DRAWSPRITES command.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
print #w.g, "drawsprites";
To cause Just BASIC graphic entities to become a permanent part of the background the program must use
the GETBMP command, and then the BACKGROUND command to reset the background. See the section
on backgrounds for more information.
COLLISION DETECTION
Most games require some form of collision detection, to ascertain when two sprites have touched. Just
BASIC does this automatically! The SPRITECOLLIDES command is used with INPUT to get a string with
names of sprites that overlap the current frame of the sprite named. The INPUT statement can be avoided if
the list receiver variable is placed inside the quotation marks for the SPRITECOLLIDES command. The
sprite names are returned in a single string with spaces between them.
OR
In the following example, the first line reports that "smiley" collided with "smiler", "smiled", and "smiles"
during that frame of animation. The second line reports that "smiley" collided with "smiler" and "smiles"
during that frame of animation. The third line reports that "smiley" collided only with the sprite named
"smiler" during that frame of animation. The fourth line reports that "smiley" did not collide with any other
sprites during that frame of animation.
Here is a picture of a sprite collision. The frog sprite has touched one of the bug sprites. Knowing this, the
program would probably change the bug sprite's visibility property to OFF and move it away from the active
playing field, or simply reset the location of the bug so that it appeared to be a new bug. If this were a game,
a point would probably be added to the score here also.
Collision detection provided by Just BASIC uses the entire sprite image, all the way to the corners, to
determine collisions.
REMOVING SPRITES
It is sometimes necessary to remove sprites from the collection of sprites so that they no longer appear and
so that they no longer trigger collisions. This might be done after a sprite collides with another sprite, so that
it is no longer in play in the game. Remove sprites with the REMOVESPRITE command.
OR
IMPORTANT REMINDER!
To avoid flickering, sprite animation is done invisibly, in memory. A frame of animation is built entirely off-
screen. A frame of animation is displayed on the screen only when the command DRAWSPRITES is called.
For each frame of animation, perform all functions to set the background image, and to set or change a
sprite's properties, then call the DRAWSPRITES command.
Sprite graphics are temporary. To learn about making sprite graphics remain in a graphicbox or graphics
window, even if the window is covered or minized, read Flushing Sprite Graphics .
Flushing Sprite Graphics
Previous Top Next
FLUSHING GRAPHICS
In Just BASIC graphicboxes and graphics windows, the drawings are lost if the window is covered by
UNREGISTERED VERSION
another window, OF CHM
or if the window TO PDFToCONVERTER
is minimized. By THETA-SOFTWARE
make drawings "stick", use the FLUSH command. The
FLUSH command is used in conjunction with DELSEGMENT, DISCARD, REDRAW, and CLS.
In the following example, the graphicbox is filled with yellow. The second line commands Just BASIC to
remember this drawing operation, and to repaint the graphicbox when needed, so that it is always filled with
yellow. Without the FLUSH command, the graphicbox reverts to its default color in any areas that were
UNREGISTERED VERSION
covered by another window,OFandCHM TO PDF
the entire CONVERTER
graphicbox reverts to itsBy THETA-SOFTWARE
default color when the window was
minimized. The FLUSH command insures that it will always be yellow.
The GETBMP comand must be followed by a DRAWBMP command that draws the named bitmap on the
window or graphicbox in the same location. It can then be FLUSHed. It looks like this in a program:
DON'T FLUSH EVERY FRAME OF A SPRITE ANIMATION! The "flush" command consumes memory.
The graphicbox can be updated easily when needed with the DRAWSPRITES command. If the sprites are
part of an animated display, each frame of animation can be flushed, but it is important to remove old
segments from memory. It is rarely necessary to flush animated graphics, because the display can be
refreshed easily, and the operations to flush and delete segments will slow down the animation.
Pauses and Timing
Previous Top Next
A REAL TIMER!
The Just BASIC TIMER is perfect for use with animation. It will cause the branch label specified to be
executed at the time interval specified in milliseconds. There are 1,000 milliseconds in one second. A half
second interval would require the milliseconds parameter to be 500. A one-quarter second interval would
require a milliseconds parameter of 250 and a one-tenth of a second interval would use a milliseconds
parameter of 100. The following example causes a frame to be drawn every one-tenth of a second:
TIMER 0
The TIMER can be activated or reactivated in the code as desired by repeating the TIMER command. The
time interval can be changed, as can the branch label to execute when the timer fires. Here is an example
that could occur in the same program as the TIMER example above:
This code will activate a one-tenth of a second pause between frames, when used after each
DRAWSPRITES command:
[loop]
scan
call Pause 100
print #w.g, "setfocus; when characterInput [quit]"
print #w.g, "when leftButtonDown [left]"
UNREGISTERED
print VERSION OFrightButtonDown
#w.g, "when CHM TO PDF CONVERTER
[right]" By THETA-SOFTWARE
gosub [drawFrame]
goto [loop]
TIMER VS PAUSE
UNREGISTERED VERSION
The TIMER causes OFlabel
a branch CHM TO
to be PDF CONVERTER
executed at a set interval, By THETA-SOFTWARE
which is measured in milliseconds.
Setting this interval to 250 (for example) will cause the branch label to be executed each one-quarter
second. A PAUSE is just that. It causes the action to pause for the set interval. Pausing for one-quarter
second BETWEEN frames of animation will not be the same as drawing a frame of animation every one-
quarter second, because in addition to the one-quarter second pause, time is taken while the code at the
branch label is executed. Using the TIMER results in much smoother and more accurate timing for
animation.
A sprite starts with a drawn image that has a black background, like this:
Create the sprite in your favorite Paint program. Change the size of the image so that it is twice as high as
the sprite, and place the sprite at the bottom. The top of the image must contain the mask. The background
for the mask must be white. Every part of the sprite that will display in the graphics animation must be
painted black in the mask. See the image of the "frog with mask" above for an example of a correctly drawn
"sprite with mask" image. You can also open the sprites included in the "SPRITES" folder to see examples of
sprites with masks.
Step by Step
Previous Top Next
Here is a step by step review of sprite animation. See a Simple Demo Program .
UNREGISTERED VERSION
1. Open a window OFaCHM
containing TO PDF
graphicbox, CONVERTER
or open By THETA-SOFTWARE
a graphics window.
2. Load bitmaps for all sprites with the LOADBMP command. (Sprite bitmaps can also be created at
runtime. For an example, see the Simple Demo Program.)
4. Optional - Load bitmap for background(s) by drawing desired background onscreen and saving it to
memory with the GETBMP command.
7. For all sprites that are to cycle through frames of animation, issue a CYCLESPRITE command.
8. For all sprites that are to have a size different from the actual bitmap image size, issue a SPRITESCALE
command.
9. For all sprites that are to appear in a different orientation, issue SPRITEORIENT commands.
10. For all sprites that are to move automatically with each frame of animation, issue a SPRITEMOVEXY
command.
DURING ANIMATION:
12. Change scale, cycling, orientation and visibilty of sprites as required by the specifics of the program with
SPRITESCALE, SPRITEORIENT SPRITEVISIBLE, SPRITECYCLE.
13. Obtain current location of desired sprites with the SPRITEXY? command.
14. Retrieve lists of sprites that have collided with designated sprites with the SPRITECOLLIDES command.
15. Place frames of animation on the screen with the DRAWSPRITES command.
Simple Demo Program
Previous Top Next
This simple demo draws a background and sprites on the screen, using GETBMP to set up the bitmaps for
sprite animation. The program moves the sprites automatically, checks for collisions and acts when the
sprites collide.
nomainwin
WindowWidth=410
WindowHeight=450
UpperLeftX=50
UpperLeftY=5
'draw background:
print #w.g, "down;fill blue"
print #w.g, "color red;backcolor red"
print #w.g, "boxfilled 200 150"
print #w.g, "getbmp landscape 0 0 399 299";
'set background:
print #w.g, "background landscape";
'masks:
print #w.s, "place 20 20;circlefilled 18"
print #w.s, "place 60 20;circlefilled 18"
'sprite 1:
print #w.s, "color yellow;backcolor yellow"
print #w.s, "place 20 60;circlefilled 18"
print #w.s, "color black;backcolor black;size 4"
print #w.s, "set 12 55;set 28 55;size 1"
print #w.s, "place 20 67"
print #w.s, "ellipsefilled 20 5"
print #w.s, "Getbmp ball1 0 0 40 80"
'sprite 2:
print #w.s, "color pink;backcolor pink"
print #w.s, "place 60 60;circlefilled 18"
print #w.s, "color blue;size 4"
print #w.s, "set 54 55;set 66 55"
print #w.s, "color darkpink;backcolor darkpink;size 1"
print #w.s, "place 60 67"
print #w.s, "ellipsefilled 20 7"
print #w.s, "Getbmp ball2 40 0 40 80"
[scroll]
if ms = 0 then wait 'this causes any extra ticks to be ignored
print #w.g, "drawsprites"
print #w.g, "spritecollides guy list$"
if list$="girl" then
print #w.g, "color black;font arial 14"
print #w.g, "place 140 280;|Boy meets girl!"
ms = timerScroll(0)
end if
wait
function timerScroll(ms)
timer ms, [scroll]
timerScroll = ms
end function
[quit]
close #w:end
Lander.bas
Previous Top Next
Here is a more advanced game that uses sprite graphics. It is a clone of the arcade game Lunar Lander.
'Lander.bas
'written by Carl Gundel
'carlg@world.std.com
'This file is contributed to the public domain
'At this stage it is merely a prototype.
'Use the keys 0 through 9 to control thrust
'Use the [ and ] keys to rotate the ship!
nomainwin
UpperLeftX = 50
UpperLeftY = 50
WindowWidth = 500
WindowHeight = 340
dim terrain(500)
open "Lunar Lander" for graphics_nsb as #lander
print #lander, "when characterInput [userInput]"
print #lander, "trapclose [quit]"
WindowWidth = 640
call makeSprites
call setBackground
print #lander, "spritexy lem 50 50"
'print #lander, "spritescale lem 200"
[startGame] 'initialize
print #lander, "setfocus"
fuel = 10000
altitude = 0
attitude = 0
longitude = 10
UNREGISTERED
thrustVERSION
= 0 OF CHM TO PDF CONVERTER By THETA-SOFTWARE
call setHorizSpeed 8
call setVertSpeed 0
call gravityAccelerate
timer 100, [timerTicked]
startTime = time$("milliseconds")
UNREGISTERED
wait VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
wait
[quit]
close #lander
end
[userInput]
char$ = Inkey$
if char$ = "[" then
attitude = attitude - 22.5
if attitude < -0.01 then attitude = 337.5
wait
end if
if char$ = "]" then
attitude = attitude + 22.5
if attitude > 337.51 then attitude = 0
wait
end if
thrustInput = instr("0123456789", char$)
if thrustInput then thrust = (thrustInput - 1) / 8 * 0.55 + 0.333
wait
end function
sub makeSprites
end sub
end sub
sub setBackground
'loadbmp "stars", "bmpbmp"
print #lander, "fill black"
call drawTerrain
print #lander, "getbmp stars 0 0 488 310"
print #lander, "background stars"
end sub
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
sub getSprite spritNum
spriteX = spritNum * 30
print #makeSprites, "getbmp lem"; spritNum; " "; spriteX; " 1 30 60"
end sub
UNREGISTERED VERSIONxSpeed
sub setHorizSpeed OF CHM TO PDF CONVERTER By THETA-SOFTWARE
vars(0) = xSpeed
end sub
function getHorizSpeed()
getHorizSpeed = vars(0)
end function
function getVertSpeed()
getVertSpeed = vars(1)
end function
sub gravityAccelerate
call setVertSpeed getVertSpeed() + 0.6'(6/18)
end sub
sub drawTerrain
[makeLandingZone]
width = int((rnd(1)*4+2)/3)
for lz = x to min(499, x + 34 * width)
terrain(lz) = y
print #lander, "goto "; lz; " "; y
next lz
x = lz
return
[endSub]
end sub
Graphical User Interface
Previous Top Next
The term "graphical user interface" is often expressed as the acronym GUI. It refers to a window and all of
its controls. These are the graphical elements that interact with the user. The user may click a button, or
UNREGISTERED VERSION
type into a textbox, OF CHM
for instance. TO PDF
The possible CONVERTER
TYPES By THETA-SOFTWARE
of windows available in Just BASIC programs are
listed in Window Types . The commands that can be sent to windows are listed in Window and Dialog
Commands . See also, Size and Placement of Windows and Trapping the Close Event . The controls
available for placement on windows are listed in Controls - Menus, Buttons, etc. Information about
handling user-generated events is given in Controls and Events . Coloring of windows and controls is
discussed in Colors and the Graphical User Interface . An explanation of the methods for sending
UNREGISTERED
commands is VERSION
discussed in OF CHM TO Syntax
Understanding PDF CONVERTER By THETA-SOFTWARE
, as well as in Sending Commands .
Just BASIC leverages the familiar statements OPEN, CLOSE, PRINT (and optionally INPUT) for working
with graphical user interface elements. For example:
It is not necessary to use the PRINT statement when issuing commands to a window or control. The word
"print" is optional, as is the comma after the window or control handle. The following version of the code
above functions identically, and requires less typing:
Printing "!trapclose [quit]" to the window tells it to use the event handler code at [quit] to decide what action
to take when the user tries to close the window. This is important. Each window OPENed should also have
a handler set up for trapping the close event.
[gotIt]
print #dialog.tbox, "!contents? name$"
notice "Hi "; name$
wait
[quit]
close #dialog
end
The "trapclose [quit]" printed to the window in this example does not need an exclamation point in front of
it. This is because the window is a dialog box, and isn't a text widget that displays text PRINTed to it. For
this reason it accepts PRINTed commands that do not start with the exclamation point.
The controls added to the window include a statictext (a non-editable label), a textbox (an editable field),
and a pushbutton. They are listed before the OPEN statement, which opens a dialog window. The button
statement's declaration includes the branch label [gotIt]. The code at [gotIt] is the button's event handler.
When the button is clicked it generates an event, and [gotIt] is invoked. The code t [gotIt] prints a command
to the textbox asking for its contents to be assigned to the string variable name$. The program then pops
up a notice window displaying a greeting to the user.
The window in the example above receives a "trapclose" command. This sets a handler for the window's
close event to be the branch label designated by "trapclose". There, the window can be closed, if
appropriate, perhaps after querying the user about what to do, for example:
[quit]
confirm "Quit. Are you sure?"; yesOrNo$
if yesOrNo$ = "yes" then [quitForSure]
wait
[quitForSure]
close #dialog
UNREGISTERED
end VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Graphical elements which display text will accept and display text that is PRINTed directly into them:
The text PRINTed to the texteditor control is displayed on the control. Because it accepts text to display, it
is necessary to prefix any commands with a ! when they are PRINTed to a text control, as the "!selectall"
command shows.
Sending Commands
Previous Top Next
See also: Understanding Syntax - how to use literals and variables in commands.
It is not necessary to use the PRINT statement when issuing commands to a window or control. The word
"print" is optional, as is the comma after the window or control handle. If these are omitted, Just BASIC
adds them in the compiling process.
The PRINT statement may only be omitted when sending commands to windows and controls. It
cannot be omitted when PRINTing to files or other devices.
The following version of the code above functions identically, and requires less typing:
In Just BASIC windows are treated like files, and anything in this class is refered to as a BASIC 'Device'.
The OPEN statement is used to OPEN a window and the CLOSE statement is used to close it. The window
UNREGISTERED VERSION
is controled with OF CHMjust
PRINT statements, TOasPDF
a file CONVERTER By THETA-SOFTWARE
is controlled by PRINT statements. (The Print statement
may be omitted when sending commands. See Sending Commands .) The commands are sent as strings
to the device. The following simple example, opens a graphics window, centers a pen (like a Logo turtle),
and draws a simple spiral. When the user attempts to CLOSE the window, he is asked to confirm the exit,
and if he agrees, the window is closed.
UNREGISTERED
button VERSION OF CHM
#graph, "Exit", TO PDF
[exit], CONVERTER
LR, 35, By THETA-SOFTWARE
20'window will have a button
open "Example" for graphics as #graph 'open graphics window
print #graph, "up" 'make sure pen is up
print #graph, "home" 'center the pen
print #graph, "down" 'make sure pen is down
[inputLoop]
input b$ 'wait for button press
[exit]
confirm "Close Window?"; answer$ 'dialog to confirm exit
if answer$ = "no" then [inputLoop] 'if answer$ = "no" loop back
close #graph
end
Handle Variables
Previous Top Next
In versions of Liberty BASIC prior to version 4, the manipulation of files and windows was done using
statically declared handles for each file, window or GUI control. Now you can create more reusable code
because handle variables allow you to pass a handle using a string form. A handle variable looks like the
regular handle but it adds a "$" on the end, like a string variable.
The handle variable maps to the string variable of the same name, which contains the actual handle. Here is
a simple example that fills the variable called "var$" with a control handle, then uses the associated handle
variable called "#var$" to send a command to the checkbox.
wait
The handle variables are most useful when accessed in FOR/NEXT loops, thus eliminating many lines of
code. They are also essential when using subroutines as event handlers, as in the TRAPCLOSE statement.
See the examples that follow.
UNREGISTERED VERSION
'set each OF CHM TO PDF CONVERTER By THETA-SOFTWARE
checkbox
for x = 1 to 5
var$ = "#win."+word$("red blue green yellow cyan", x)
#var$ "set"
next x
wait
Understanding Syntax
Previous Top Next
The documentation for Just BASIC commands includes command definitions in example form. These are
not to be taken literally. The language used attempts to give intuitive labels to the command parameters.
For example, finding an "x" within a command definition doesn't meant that an actual "x" should appear
there, but rather that the value desired for the x placement should appear there. Here are some examples
to explain the way it works.
Graphics Commands
In the following graphics command definition, the "x" and "y" are NOT variables, but placeholders for hard-
coded values.
In an actual program, the values required would appear within the quotation marks for the command:
To use the "x" and "y" as variables, they MUST be placed outside the quotation marks, with blank spaces
preserved within quotation marks:
x = 30
y = 221
print #main, "box ";x;" ";y
Text Commands
Text commands must be preceded by the ! character. If not, they will simply be displayed in the textbox,
texteditor or text window as text. In the example above, "column" and "row" are standing in for hard coded
values.
OR
a = 3 : b = 4
print #win, "!origin ";a;" ";b
Control Commands
x = 112 : y = 34
BUTTON #1.2, "Print", [printClick], UL, x, y
As it appears in a program:
The size and placement of any window can be set before it is opened. If no size and placement statements
are specified before a statement to OPEN a window, Just BASIC will pick default sizes.
There are four special variables that can be set to select the size and placement of windows:
UpperLeftX
UpperLeftY
WindowWidth
WindowHeight
The width and the height of the display screen can be retrieved with these variables:
DisplayWidth
DisplayHeight
The values set for UpperLeftX and UpperLeftY determine the number of pixels from the upper-left corner of
the screen to position the window. Often determining the distance from the upper-left corner of the screen
is not as important as determining the size of the window. If UpperLeftX and UpperLeftY values are not set,
the window will appear at a default location determined by Windows.
WindowWidth and WindowHeight can be set to the number of pixels wide and high desired for window.
These must be set before the OPEN statement for the window. Once the size and placement of a window
are set, the window may be opened with an OPEN statement. Here is an example:
[openStatus]
UpperLeftX = 32
UpperLeftY = 52
WindowWidth = 190
WindowHeight = 160
This will open a window 32 pixels from the left side of the screen and 52 pixels from the top of the screen,
and with a width of 190 pixels, and a height of 160 pixels.
The screen resolution is contained in the special variables DisplayWidth and DisplayHeight. A screen
resolution of 800x600 pixels returns values of 800 and 600 respectively for DisplayWidth and DisplayHeight.
The sample code below prints the current screen resolution:
DisplayWidth and DisplayHeight can be used to compute values for WindowWidth and WindowHeight, as in
these examples:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight - 100
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Just BASIC provides different kinds of window types. Controls can be added to these windows as needed
(see help section Controls - Menus, Buttons, Etc .). Here are the kinds of windows and the commands
associated with them:
Style suffixes for window types (not all suffixes are supported for each window type):
Window
Windows of type "window" are the most used and useful windows used by Just BASIC programmers. They
can contain any of the controls. They can have a sizing frame, or omit it. They can include a menu, but they
do not have to have a menu. It is also possible for the user to hit the TAB key to move focus from one
control to the next in a window of type "window."
Graphics
Windows of type "graphics" are especially suited to displaying graphics and graphical sprites. They are not
intended to contain controls, and some controls do not work properly when placed in a graphics window. A
sizing frame and scrollbars are optional in a graphics window.
Dialog
Windows of type "dialog" are similar to windows of type "window" in that they can contain all of the other
controls except menus. Menus cannot be placed on a dialog window. Dialog windows allow the user to hit
the TAB key to move focus from one control to the next. A dialog can have a default button that is activated
when the user hits the ENTER key. For this reason, texteditors do not work well in dialog windows,
because hitting ENTER is trapped by the window and the user cannot add a carriage return to text in a
texteditor. Dialog windows are best suited for getting information from a user, although it is possible to have
applications that are dialog-based. Dialog windows may display as "modal." This means that they receive
the input focus for the program until they are closed. Other program windows cannot be accessed by a
user while a modal dialog is displayed.
Text
Windows of type "text" are quite limited in their functionality. They are not meant to contain other controls.
They are useful for displaying text to a user, or for allowing a user to write and edit text. Text windows
always have a menubar that contains a ready-made File Menu and a ready-made Edit Menu.
Window types:
Text Commands
Here are the details for Just BASIC commands that add menus, buttons, listboxes, and more.
Bmpbutton
Button
Checkbox
Combobox
Graphicbox
Groupbox
Listbox
Menu
Radiobutton
Statictext
Textbox
Texteditor
Control Descriptions
A BMPBUTTON is a clickable button that displays an image. Bmpbuttons allow users to give a command to
a program.
A BUTTON is a clickable button with a text label. Buttons allow users to give a command to a program.
A CHECKBOX is a small box that can be checked or unchecked by the user, or by the programmer. It
displays a text label. A checkbox is used when giving a user options from which to choose.
A COMBOBOX is a form of list. It displays on the window as a small textbox with an arrow at the side. When
the user clicks the arrow, the list drops down and the user can make a selection. A combobox is appropriate
when a program must give the user a list of choices, but there isn't much room on the window to display a
list.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
A GRAPHICBOX is a box that displays graphics, such as bitmap images, or drawn objects like circles and
lines, or even text. A graphicbox is used to give the user a graphic display, such as showing a bitmap
image, drawing a graph or chart, or simply to add visual interest to a program.
A GROUPBOX consists of a label and a box. The box can contain other controls, so that they may be
grouped for easy identification. Radiobuttons within a groupbox function as a set. To have multiple sets of
radiobuttons in a window, each set must be placed in its own groupbox.
A LISTBOX is a form of list. It appears as a list of items in a box on the window. The user may make a
choice by clicking on an item in the list with the mouse. If there are more items in the list than there is room
in the listbox, the listbox will automatically add scrollbars. A listbox is a good choice when it is necessary to
give the user a list of choices.
A MENU is a dropdown list of user commands that appears on a bar below the titlebar of a window. The user
clicks on an item contained in the dropdown list to give the window a command.
A RADIOBUTTON is a small round box that can be clicked by the user. It has a text label. Radiobuttons
function in groups. When the user clicks a radiobutton, that button's circle is filled in and all other
radiobuttons are cleared. The programmer may set or unset a radiobutton in code also. A radiobutton is
used when a user must choose only one possibility from a group of possibilities.
A STATICTEXT is a simple text label used to give information to the user. The user cannot interact with a
statictext control.
A TEXTBOX is a small box that contains text. Text can be placed in the textbox by the programmer, or the
user can type into the textbox. A textbox is used to get a small amount of text input from the user, or to
display a small amount of text.
A TEXTEDITOR is a large box with both horizontal and vertical scrollbars. Text can be placed in the
texteditor by the programmer, or the user can type into the texteditor. A texteditor is used to get a large
amount of text input from the user, or to display a large amount of text.
Controls and Events
Previous Top Next
The commands to create a controls must specify event handlers that are associated with user actions made
on those controls (clicking, double-clicking, selecting, etc.). There are two ways to set up event handlers. A
branch label may be specified as an event handler, or a subroutine may be specified as an event handler. A
UNREGISTERED
program may VERSION OF CHMorTO
use either subroutines PDF CONVERTER
branchlabels By as
or a combination THETA-SOFTWARE
event handers. Both ways are
discussed below.
Just BASIC can only respond to events when execution is halted at in INPUT or WAIT statement, or when a
SCAN command is issued. Here is a short program:
nomainwin
button #1, " &Ok ", [quit], UL, 120, 90
checkbox #1.cb, "I am a checkbox", [set], [reset], 10, 10, 130, 20
button #1, " Set ", [setCheckBox], UL, 10, 50, 40, 25
button #1, " Reset ", [resetCheckBox], UL, 60, 50, 50, 25
textbox #1.text, 10, 90, 100, 24
WindowWidth = 190
WindowHeight = 160
open "Checkbox test" for dialog as #1
wait
[setCheckBox]
print #1.cb, "set"
[set]
print #1.cb, "value? t$"
print #1.text, "I am "; t$
wait
[resetCheckBox]
print #1.cb, "reset"
[reset]
print #1.cb, "value? t$"
print #1.text, "Checkbox is "; t$
wait
[quit]
close #1
end
In the above code, Just BASIC opens a small window with a checkbox, a textbox, and a few buttons. After
that, it stops at the WAIT statement just after the branch label [waitHere]. At this time, if the user clicks one
of the buttons or the checkbox, Just BASIC can handle the event and go to the appropriate branch label.
The code can be observed in action by stepping through it with the debugger.
This adds a button to the window (#main) labeled "Accept". When the program is run, and the user clicks on
this button, then execution calls the subroutine userAcceptsSub, passing the handle of the button as an
argument to the subroutine.
gosub [loadData]
listbox #win.pets, pet$(), [selectPet], 10, 10, 140, 150
listbox #win.vehicles, vehicle$(), [selectVehicle], 150, 10, 150, 150
statictext #win.label, "", 10, 170, 300, 25
open "Branch label handler" for window as #win
#win.pets "singleclickselect [selectPet]"
#win.vehicles "singleclickselect [selectVehicle]"
wait
[selectPet]
#win.pets "selection? item$"
print #win.label, "Pet -> "; item$
wait
[selectVehicle]
#win.vehicles "selection? item$"
print #win.label, "Vehicle -> "; item$
wait
[loadData]
for x = 0 to 2
read a$
pet$(x) = a$
next x
for x = 0 to 2
read a$
vehicle$(x) = a$
next x
return
end
gosub [loadData]
listbox #win.pets, pet$(), selectionMade, 10, 10, 140, 150
listbox #win.vehicles, vehicle$(), selectionMade, 150, 10, 150, 150
statictext #win.label, "", 10, 170, 300, 25
open "Branch label handler" for window as #win
UNREGISTERED VERSION
#win.pets OF CHM TO PDF
"singleclickselect CONVERTER By THETA-SOFTWARE
selectionMade"
#win.vehicles "singleclickselect selectionMade"
wait
[loadData]
for x = 0 to 2
read a$
pet$(x) = a$
next x
for x = 0 to 2
read a$
vehicle$(x) = a$
next x
return
end
Window and Dialog Commands
Previous Top Next
Note that Just BASIC allows tabbing through controls in windows of type "window" as well as in windows of
type "dialog." "Tabbing through the controls" means that controls will be highlighted and receive the input
focus, in turn each time the user hits the "TAB" key. When the user presses the "TAB" key, the next control
listed will receive the input focus.
The "default" extension only works this way for regular buttons, not for bmpbuttons.
If any button has focus, it becomes the default button in a dialog window. If any other kind of control has the
focus, the button designated with the ".default" extension is the default button.
TRAPCLOSE - This command sets a close event handler for a window or dialog. When a user decide to
close a window, it branches to a routine specified by the "trapclose" command that confirms or does some
sort of cleanup, etc.
[branch]
confirm "Really close?"; answer$
if answer$ = "no" then wait
close #example
end
To send a trapclose command to text window, precede the command with the ! character.
FONT - This command sets the font of all of the controls in a window.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
'set the font of all the controls in a
'window to courier new 8pt italic
print #handle, "font courier_new 8 italic"
To override this general font command, font commands may be sent to individual controls after this
command is issued. See the command lists for individual controls for control-specific documentation. If a
control can accept a new text string such as a caption, the font command must be preceded by a !
character. Examples:
SETFOCUS - Input focus can be set to a control, or to a window with this command. This means that
keyboard input will be directed to the specified control or window. Begin the command with the ! character
for all windows and controls that can accept new text strings, or the command will simply be displayed on the
control. See the topics for individual controls for control-specific documentation.
'texteditor
print #handle.texteditor, "!setfocus"
'graphics window
print #graph, "setfocus"
'button
print #handle.button, "!setfocus"
'graphicbox
print #handle.graphicbox, "setfocus"
ENABLE, DISABLE
These two commands cause a control to be enabled and active, or disabled and inactive. When a control is
disabled it appears to be grayed-out. Begin the command with the ! character for all windows and controls
that can accept new text strings, or the command will simply be displayed on the control. See the topics for
individual controls for control-specific documentation.
nomainwin
wait
[doEnable]
#win.bttn "!Enable"
#win.cbox "Enable"
wait
[doDisable]
#win.bttn "!Disable"
#win.cbox "Disable"
wait
[hello] wait
Trapping the Close Event
Previous Top Next
It is important for Just BASIC program windows to trap the close event. Then when a user tries to close a
window, program flow is directed to an event handler that the program specifies. At that place the program
UNREGISTERED VERSION
can ask for verification thatOF
the CHM
windowTO PDF
should beCONVERTER By THETA-SOFTWARE
closed, and/or perform some sort of cleanup (close files,
write ini data, set a flag that the window is open or closed, etc.). There may be a menu item or button that
a user can click to close the window, but the user might also click the X closing button or the system close
button, and that is the event trapped by the trapclose statement.
This will tell Just BASIC to use the code at [branchLabel] as an event handler for the window with the
handle #myWindow, continuing execution of the program there if the user tries to close the window (see
buttons1.bas example below). If the subroutine, subLabel is designated as the event handler, rather than a
branch label, the named subroutine is executed when the close event is triggered. The handle of the
window is passed into the subroutine by Just BASIC.
And then the code that is executed when the window is closed looks like this:
[quit]
confirm "Do you want to quit Buttons?"; quit$
if quit$ = "no" then wait
close #1
end
And then the code that is executed when the window is closed looks like this:
sub Quit handle$
confirm "Do you want to quit Buttons?"; quit$
if quit$ = "no" then wait
close #handle$
end
end sub
Colors and the Graphical User Interface
Previous Top Next
By default, Just BASIC gives windows and controls standard colors from the user's Windows Control Panel
settings. Several special variables are provided to change the colors of certain windows and controls.
UNREGISTERED VERSION
These variables OF CHM
are case sensitive, TO
and PDF
must CONVERTER
be typed in the properBy THETA-SOFTWARE
case. For example,
"backgroundcolor$" is not the same as "BackgroundColor$". The following code creates a window with a
dark blue background and light gray text. It does this by setting the BackgroundColor$ and
ForegroundColor$ variables BEFORE OPENING THE WINDOW:
Setting BackgroundColor$ sets the color of the background of the window, and of groupboxes, checkboxes,
radiobuttons and statictext controls. Setting the ForegroundColor$ sets the color of text displayed in all
controls. Only the last ForegroundColor$ and BackgroundColor$ values set before a window is opened are
valid for that window. Other special color variables exist for setting the background color of several widgets:
TextboxColor$
ComboboxColor$
ListboxColor$
TexteditorColor$
WindowWidth = 550
WindowHeight = 410
TextboxColor$ = "red"
textbox #main.textbox1, 26, 16, 100, 25
TextboxColor$ = "blue"
textbox #main.textbox2, 30, 61, 100, 25
TextboxColor$ = "yellow"
textbox #main.textbox3, 30, 121, 100, 25
open "untitled" for dialog as #main
[main.inputLoop] 'wait here for input event
wait
black, blue, brown, buttonface, cyan, darkblue, darkcyan, darkgray, darkgreen, darkpink, darkred, green,
lightgray,
palegray, pink, red, white, yellow
"Palegray" and "Lightgray" are different names for the same color. "Buttonface" is the default background
color currently set on a user's system, so it will vary according to the desktop color scheme. The
colornames are not case sensitive, so "WHITE" is the same as "white." Here is a graphical representation of
the available colors:
How to Specify Fonts
Previous Top Next
In Just BASIC there are many places to specify fonts. This is done using a font command string
UNREGISTERED
containing: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
In the above example, the line print #fontExample, "font arial 14 italic" contains a font specification.
Everything after the word font is the specifier: arial 14 italic.
Font Specifications
FaceName
The facename is case insensitive, so "Arial" is the same as "ARIAL" and "arial." To specify a font which
has spaces in its name, use underscores like this:
Courier New
becomes...
Size in Points
Specify a point size as above by using a single size parameter. A "point" is 1/72 of an inch, so there are
72 points in an inch. A font that is 14 points high is not the same size as a font that is 14 pixels high.
Size in Pixels
To specify font size by pixel rather than by point, include parameters for both width and height in the font
command. If the width parameter is set to 0, the default width for that font face and height will be used.
Here are some examples that set font size by point and by pixel:
'specify just a point size with a single size parameter
print #fontExample, "font Arial 14"
Attributes
Any or all of these attributes (modifiers) can be added - italic, bold, strikeout, and underscore:
Just BASIC has several built-in dialogs that allow the program's user to make choices or to enter a small
amount of text. They are as follows:
UNREGISTERED
FILEDIALOG VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This dialog activates the Windows Common File Dialog that allows a user to select a disk filename to open
or save.
NOTICE
This dialog gives the user a message and it includes an OK button. It stays onscreen until the user clicks
the OK button.
PROMPT
This dialog has a brief text message and a textbox that allows a user to enter a small amount of text. It also
contains an OK button and a CANCEL button.
Please see the topics for the individual dialogs for pictures and details on their use.
Sounds
Previous Top Next
BEEP
The BEEP command plays the system default wav file. This is often a DING sound. See BEEP .
PLAYWAVE
The PLAYWAVE command plays a wav sound file on disk. See PLAYWAVE .
PLAYMIDI
The PLAYMIDI command plays a midi sound file on disk. See PLAYMIDI .
Mouse, Keyboard and Joystick
Previous Top Next
Just BASIC can read mouse events and keyboard input when a graphics window or graphicbox is used. See
Reading Mouse Events and Keystrokes .
UNREGISTERED VERSION
Just BASIC can read the x,OF CHM
y, and TO PDF of
z coordinates CONVERTER By and
up to two joysticks, THETA-SOFTWARE
it can read the status of the
joystick buttons. See READJOYSTICK .
COMMAND REFERENCE:
A-C D-F G-K L-M N-P R-S T-Z
Command Reference G-K
Previous Top Next
MAINWIN set the width of the main window in columns and rows
MENU adds a pull-down menu to a window
MID$( ) return a substring from a string
MIDIPOS( ) return position of play in a MIDI file
MKDIR( ) make a new subdirectory
MOD returns the result of integer division
"!modified?" text command to return modified status
Command Reference:
A-C D-F G-K L-M N-P R-S T-Z
Command Reference N-P
Previous Top Next
Command Reference:
A-C D-F G-K L-M N-P R-S T-Z
Command Reference R-S
Previous Top Next
Command Reference:
A-C D-F G-K L-M N-P R-S T-Z
Command Reference T-Z
Previous Top Next
Command Reference:
A-C D-F G-K L-M N-P R-S T-Z
Additional Commands
Previous Top Next
AND, APPEND, AS, BEEP, BMPBUTTON, BMPSAVE, BOOLEAN, BUTTON, BYREF, CALL, CASE,
CHECKBOX, CLOSE, CLS, COMBOBOX, CONFIRM, DATA, DIALOG, DIM, DO, DUMP, ELSE, END,
UNREGISTERED VERSION
ERROR, EXIT, OF CHM FILES,
FIELD, FILEDIALOG, TO PDF CONVERTER
FOR, By GLOBAL,
FUNCTION, GET, THETA-SOFTWARE
GOSUB, GOTO,
GRAPHICBOX, GRAPHICS, GROUPBOX, IF, INPUT, KILL, LET, LINE, LISTBOX, LOADBMP, LONG,
LOOP, LPRINT, MAINWIN, MAPHANDLE, MENU, NAME, NEXT, NOMAINWIN, NONE, NOTICE, ON,
ONCOMERROR, OR, OPEN, OUTPUT, PLAYMIDI, PLAYWAVE, PRINT, PROMPT, PUT,
RADIOBUTTON, RANDOM, RANDOMIZE, READ, READJOYSTICK, REDIM, REM, RESTORE, RETURN,
RUN, SCAN, SELECT, STATICTEXT, STOP, STOPMIDI, SUB, TEXT, TEXTBOX, TEXTEDITOR, THEN,
UNREGISTERED VERSION
TIMER, UNLOADBMP, OF CHM
UNTIL, WAIT, TO PDF CONVERTER
WINDOW, By THETA-SOFTWARE
WEND, WHILE, WORD, XOR
FUNCTIONS:
Note that the opening parenthesis is part of the function name:
ABS(, ACS(, ASC(, ASN(, ATN(, CHR$(, COS(, DATE$(, EOF(, EXP(, INPUT$(, INSTR(, INT(, LEFT$(,
LEN(, LOF(, LOG(, LOWER$(, MIDIPOS(, MID$(, MKDIR(, NOT(, RIGHT$(, RMDIR(, RND(, SIN(,
SPACE$(, SQR(, STR$(, TAB(, TAN(, TIME$(, TRIM$(, TXCOUNT(, UPPER$(, USING(, VAL(, WORD$(
VARIABLES:
Description:
This function returns | n | (the absolute value of n). "n" can be a number or any numeric expression.
Usage:
Description:
This function returns the arc cosine of the number or numeric expression n. The return value is expressed in
UNREGISTERED
radians. VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
Description:
This function returns the ASCII value of the first character of string s$. s$ can be a string variable , or text
enclosed in quotes. Text and formatting characters have ASCII values from 0 to 255. See also CHR$( n )
Usage:
Chr$(33) = !
Chr$(34) = "
Chr$(35) = #
Chr$(36) = $
Chr$(37) = %
Chr$(38) = &
Chr$(39) = '
Chr$(40) = (
Chr$(41) = )
Chr$(42) = *
Chr$(43) = +
Chr$(44) = ,
Chr$(45) = -
Chr$(46) = .
Chr$(47) = /
Chr$(48) = 0
Chr$(49) = 1
Chr$(50) = 2
Chr$(51) = 3
Chr$(52) = 4
Chr$(53) = 5
Chr$(54) = 6
Chr$(55) = 7
Chr$(56) = 8
Chr$(57) = 9
Chr$(58) = :
Chr$(59) = ;
Chr$(60) = <
Chr$(61) = =
Chr$(62) = >
Chr$(63) = ?
Chr$(64) = @
Chr$(65) = A
Chr$(66) = B
Chr$(67) = C
Chr$(68) = D
Chr$(69) = E
Chr$(70) = F
Chr$(71) = G
Chr$(72) = H
Chr$(73) = I
UNREGISTERED
Chr$(74) =VERSION
J OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Chr$(75) = K
Chr$(76) = L
Chr$(77) = M
Chr$(78) = N
Chr$(79) = O
UNREGISTERED
Chr$(80) =VERSION
P OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Chr$(81) = Q
Chr$(82) = R
Chr$(83) = S
Chr$(84) = T
Chr$(85) = U
Chr$(86) = V
Chr$(87) = W
Chr$(88) = X
Chr$(89) = Y
Chr$(90) = Z
Chr$(91) = [
Chr$(92) = \par Chr$(93) = ]
Chr$(94) = ^
Chr$(96) = `
Chr$(97) = a
Chr$(98) = b
Chr$(99) = c
Chr$(100) = d
Chr$(101) = e
Chr$(102) = f
Chr$(103) = g
Chr$(104) = h
Chr$(105) = i
Chr$(106) = j
Chr$(107) = k
Chr$(108) = l
Chr$(109) = m
Chr$(110) = n
Chr$(111) = o
Chr$(112) = p
Chr$(113) = q
Chr$(114) = r
Chr$(115) = s
Chr$(116) = t
Chr$(117) = u
Chr$(118) = v
Chr$(119) = w
Chr$(120) = x
Chr$(121) = y
Chr$(122) = z
Chr$(123) =
Chr$(124) = |
Chr$(125) =
Chr$(126) = ~
Chr$(127) =
Chr$(128) =
Chr$(129) =
Chr$(130) =
Chr$(131) =
Chr$(132) =
Chr$(133) =
Chr$(134) =
Chr$(135) =
Chr$(136) =
Chr$(137) =
Chr$(138) =
Chr$(139) =
Chr$(140) =
Chr$(142) =
Chr$(145) = '
Chr$(146) = '
Chr$(147) =
Chr$(148) =
Chr$(149) =
Chr$(150) =
Chr$(151) =
Chr$(152) =
Chr$(153) =
Chr$(154) =
Chr$(155) =
Chr$(156) =
Chr$(158) =
Chr$(159) =
Chr$(161) =
Chr$(162) =
Chr$(163) =
Chr$(164) =
Chr$(165) =
Chr$(166) =
Chr$(167) =
Chr$(168) =
Chr$(169) =
Chr$(170) =
Chr$(171) =
Chr$(172) =
Chr$(173) =
Chr$(174) =
Chr$(175) =
Chr$(176) =
Chr$(177) =
Chr$(178) =
Chr$(179) =
Chr$(180) =
Chr$(181) =
Chr$(182) =
Chr$(183) =
Chr$(184) =
Chr$(185) =
Chr$(186) =
Chr$(187) =
Chr$(188) =
Chr$(189) =
Chr$(190) =
Chr$(191) =
Chr$(192) =
UNREGISTERED
Chr$(193) VERSION
= OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Chr$(194) =
Chr$(195) =
Chr$(196) =
Chr$(197) =
Chr$(198) =
UNREGISTERED
Chr$(199) VERSION
= OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Chr$(200) =
Chr$(201) =
Chr$(202) =
Chr$(203) =
Chr$(204) =
Chr$(205) =
Chr$(206) =
Chr$(207) =
Chr$(208) =
Chr$(209) =
Chr$(210) =
Chr$(211) =
Chr$(212) =
Chr$(213) =
Chr$(214) =
Chr$(215) =
Chr$(216) =
Chr$(217) =
Chr$(218) =
Chr$(219) =
Chr$(220) =
Chr$(221) =
Chr$(222) =
Chr$(223) =
Chr$(224) =
Chr$(225) =
Chr$(226) =
Chr$(227) =
Chr$(228) =
Chr$(229) =
Chr$(230) =
Chr$(231) =
Chr$(232) =
Chr$(233) =
Chr$(234) =
Chr$(235) =
Chr$(236) =
Chr$(237) =
Chr$(238) =
Chr$(239) =
Chr$(240) =
Chr$(241) =
Chr$(242) =
Chr$(243) =
Chr$(244) =
Chr$(245) =
Chr$(246) =
Chr$(247) =
Chr$(248) =
Chr$(249) =
Chr$(250) =
Chr$(251) =
Chr$(252) =
Chr$(253) =
Chr$(254) =
Chr$(255) =
ASN( n )
Previous Top Next
Description:
This function returns the arc sine of the number or numeric expression n. The return value is expressed in
UNREGISTERED
radians. VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
Description:
This function returns the arc tangent of the number or numeric expression n. The return value is expressed
in radians.
Usage:
Tip:
There are 2 * pi radians in a full circle of 360 degrees. A formula to convert degrees to radians is: radians =
degrees divided by 57.29577951
Description:
This command will play the default system wave file. The actual sound played depends upon the default
UNREGISTERED
sound schemeVERSION
on the user'sOF CHM TO
computer. PDF
This CONVERTER
sound ByasTHETA-SOFTWARE
is best described a 'ding'. Program execution will stop
until the wave file is finished playing.
Usage:
Description:
This statement adds a button that displays an image to a window created with the OPEN command.
Usage:
The BMPBUTTON statement must be listed before the statement to OPEN the window that will contain it.
Here is a brief description for each parameter as listed above:
#handle.ext
The #handle must be identical to the handle of the window which will contain the bmpbutton. The bmpbutton
may have an optional, unique extension which allows it to receive commands during program execution.
The extension begins with a dot and may include any alpha-numeric characters. A bmpbutton contained on
a window whose handle is #win will have #win as the first part of its handle. Examples of bmpbutton
handles are as follows:
filespec
The filespec parameter contains the full or relative path and filename of the *.bmp file containing the bitmap
image that will appear on the button. There are no width or height parameters in the bmpbutton statement,
so the size of the button cannot be set by the program. It is determined by the size of the bitmap image that
will appear on it. See also Path and Filename .
returnVar
returnVar is expressed as one word and it is not enclosed in quotes. It cannot be expressed as a string
variable. It must begin with a letter, but it can contain numerals as well. If returnVar is set to a valid branch
label enclosed in square brackets, then a button click will cause program execution to continue at the
specified branch label. The code that follows the branch label will be executed when the button is pressed.
If returnVar is the name of a subroutine, then that subroutine will be activated when the button is clicked, and
the button handle will be passed into the subroutine as an argument.
If returnVar is not a valid branch label or subroutine name, then the value of returnVar is available to be read
when the program is halted at an input var$ statement. The value will be placed into the specified variable.
An example appears below.
corner
This parameter must be one of the following: UL, UR, LL, or LR. It specifies which corner of the window
acts as an anchor for the button. For example, if LR is used, then the button will be located relative to the
lower right corner. If the window size is changed during execution of the program, the button will always
appear at the same position, relative to the corner specified as the anchor.
UL = upper left
UR = upper right
LL = lower left
LR = lower right
posx, posy
These parameters set the location for the button relative to the anchor corner. posx and posy are expressed
in pixels. Anchor values of less than one may also be used for posx and posy. For example, if the anchor
corner is UL, posx is .9, and posy is .9, then the button will be positioned 9/10ths of the distance of the
window in both x and y from the upper left corner. This method of positioning buttons places them in
UNREGISTERED
positions that VERSION
are relative toOF
theCHM
size ofTO
the PDF CONVERTER
window, By THETA-SOFTWARE
rather than anchoring them to a specified corner.
SAMPLE PROGRAMS
[loop]
wait
[arrowClicked]
notice "The arrow button was clicked. Goodbye."
close #main
end
[loop]
wait
[quit]
close #main
end
BMPBUTTON COMMANDS
'bitmap.bas
'demonstrate the bitmap command for bmpbuttons
'clicking the buttons causes the bitmap images
'displayed on the buttons to change
WindowWidth = 248
WindowHeight = 175
nomainwin
loadbmp "arrow", "bmpbmp"
loadbmp "blue", "bmpbmp"
bmpbutton #main.button1, "bmpbmp", [button1Click], UL, 22, 11
bmpbutton #main.button2, "bmpbmp", [button2Click], UL, 22, 46
open "BmpButton Image Changer" for window as #main
print #main, "trapclose [quit]"
[quit]
close #main
end
Description:
This saves a named bitmap to the specified filename. The named bitmap can be obtained either from the
LOADBMP command or the GETBMP graphics command. The bitmap will be saved to disk in the same
resolution as the user's display resolution. If the user's display is setup for 32-bit color, then the bitmap will
be in 32-bit format, for instance. If a full path isn't given for the saved bitmap, it will be saved in the
program's DefaultDir$ .
Usage:
[quit]
close #1
end
BUTTON
Previous Top Next
UNREGISTERED VERSION
BUTTON #handle.ext, OF returnVar,
"label", CHM TOcorner,
PDF x,
CONVERTER
y , width, heightBy THETA-SOFTWARE
Description:
This statement adds a button that has a text label to a window created with the OPEN command. The width
and height parameters are optional.
UNREGISTERED
Usage: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
The BUTTON statement must be listed before the statement to OPEN the window that will contain it. Here is
a brief description for each parameter as listed above:
#handle.ext
The #handle must be identical to the handle of the window which will contain the button. The button may
have an optional, unique extension which allows it to receive commands during program execution. The
extension begins with a dot and may include any alpha-numeric characters. A button contained on a window
whose handle is #win will have #win as the first part of its handle. Examples of button handles are as
follows:
"label"
This parameter specifies the caption that will appear on the button. It may be expressed as a literal text
string, or as a string variable. See String Literals and Variables .
returnVar
returnVar is expressed as one word and it is not enclosed in quotes. It cannot be expressed as a string
variable. It must begin with a letter, but it can contain numerals as well. If returnVar is set to a valid branch
label enclosed in square brackets, then a button click will cause program execution to continue at the
specified branch label. The code that follows the branch label will be executed when the button is pressed.
If returnVar is the name of a subroutine, then that subroutine will be activated when the button is clicked, and
the button handle will be passed into the subroutine as an argument. See also: Controls and Events
If returnVar is not a valid branch label or subroutine name, then the value of returnVar is available to be read
when the program is halted at an input var$ statement. The value will be placed into the specified variable.
An example appears below.
corner
This parameter must be one of the following: UL, UR, LL, or LR. It specifies which corner of the window
acts as an anchor for the button. For example, if LR is used, then the button will be located relative to the
lower right corner. If the window size is changed during execution of the program, the button will always
appear at the same position, relative to the corner specified as the anchor.
UL = upper left
UR = upper right
LL = lower left
LR = lower right
posx, posy
These parameters set the location for the button relative to the anchor corner. posx and posy are expressed
in pixels. Anchor values of less than one may also be used for posx and posy. For example, if the anchor
corner is UL, posx is .9, and posy is .9, then the button will be positioned 9/10ths of the distance of the
window in both x and y from the upper left corner. This method of positioning buttons places them in
positions that are relative to the size of the window, rather than anchoring them to a specified corner.
width, height
These optional parameters specify how wide and high the button will be, measured in pixels. If these
parameters are not used in the BUTTON statement, then Just BASIC will set the size of the button to be
large enough to display the text label specified.
[loop]
wait
[exitClicked]
notice "The Exit button was clicked. Goodbye."
close #main
end
[loop]
wait
[loop]
input answer$
if answer$ = "yes" then notice "You clicked Okay."
if answer$ = "no" then notice "You clicked Cancel."
goto [loop]
[quit]
close #main
end
Default Button
A window of type DIALOG can contain a button with the extension ".default". If the user presses the ENTER
key while the dialog window has focus, it is the same as if the button whose extension is "default" is pressed
UNREGISTERED VERSION
and program execution willOF CHMatTO
continue the PDF
event CONVERTER By THETA-SOFTWARE
handler [branchLabel] for that button. In the example
below, the program will branch to the [okay] routine when the user presses ENTER.
Button commands:
Example:
Usage:
Each of the parameters in the function and sub in this example use the "byref" specifier. This means that
when the value of a and b are changed in the function that the variables used to make the call (x and y) will
also be changed to reflect a and b when the function returns. Try stepping through this example in the
debugger.
end
a$(0) = "snoopy"
call capitalize a$(0)
end
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
function formatAndTruncateXandY$(byref a, byref b)
a = int(a)
b = int(b)
formatAndTruncateXandY$ = str$(a)+", "+str$(b)
end function
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
sub capitalize byref word$
word$ = upper$(left$(word$, 1))+mid$(word$, 2)
end sub
CALL
Previous Top Next
Description:
This command invokes a user defined subroutine. Call is followed by the name of the subroutine and by
zero or more string and/or numeric expressions.
Here is a description
UNREGISTERED VERSION of theOF
parameters
CHM TO of the
PDFCHECKBOX statement:
CONVERTER By THETA-SOFTWARE
#handle.ext
This parameter specifies the handle for this control. The #handle part should be the same as the handle of
the window containing the checkbox, and the .ext part names the checkbox uniquely in the window.
"label"
This parameter contains the visible text of the checkbox
setHandler
This is the branch label or subroutine to go to when the user sets the checkbox by clicking on it. When the
checkbox is "set" it displays a checkmark. See also: Controls and Events
resetHandler
This is the branch label or subroutine to goto when the user resets the checkbox by clicking on it. When the
checkbox is "reset", the checkmark is removed. See also: Controls and Events
x
This is the x position of the checkbox relative to the upper left corner of the window it belongs to.
y
This is the y position of the checkbox relative to the upper left corner of the window it belongs to.
wide
This is the width of the checkbox control.
high
This is the height of the checkbox control.
Checkbox Commands
Checkboxes understand these commands:
Example:
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
Usage
Here are sample programs that use checkboxes.
WindowWidth = 180
WindowHeight = 160
[inputLoop]
input r$
[set]
print #1.cb, "set"
goto [readCb]
[reset]
print #1.cb, "reset"
goto [readCb]
end
[readCb]
print #1.cb, "value?"
input #1.cb, t$
print #1.text, "I am "; t$
goto [inputLoop]
UNREGISTERED VERSION
WindowWidth OF CHM TO PDF CONVERTER By THETA-SOFTWARE
= 180
WindowHeight = 160
open "Checkbox test" for dialog as #1
print #1, "trapclose [quit]"
[inputLoop]
input r$
Description:
This function returns a one-character-long string, consisting of the character represented on the ASCII table
by the value n (0 - 255).
Usage:
print chr$(77)
print chr$(34)
print chr$(155)
Produces:
M
"
CLOSE #h
Previous Top Next
Description:
This command is used to close files and devices. This is the last step of a file "read" and/or "write"
UNREGISTERED
operation, andVERSION OFtoCHM
it is also used TO PDFthat
close windows CONVERTER By THETA-SOFTWARE
have been opened. When execution of a program is
complete, if there are any files or devices left open, Just BASIC displays a dialog explaining that it was
necessary to close the opened files or devices. This is designed as an aid so that the programmer can
correct the problem. If for some reason the programmer chooses to terminate the program early (this is done
by closing the program's main window before the program finishes), then Just BASIC will close any open
files or devices without posting a notice to that effect.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
Description:
This command clears the mainwin of text and sets the cursor back at the upper left hand corner. It is useful
for providing a visual break to separate different functional sections of a program. Additionally, since the
main window doesn't actually discard past information on its own, the CLS command can be used to reclaim
memory from a program by forcing the main window to dump old text.
Usage:
Description:
Comboboxes are a lot like listboxes , but they are designed to save space. Instead of showing an entire list
of items, they show only the selected one. When the user clicks on the checkbox arrow button (to the right),
a list appears (drops down). It is then possible to browse the possible selections, and pick one if so desired.
When the selection is made, the new selection is highlighted. The user can type into the textbox part on top
of the combobox, rather than choosing an item from the dropdown list. The program can get the contents of
this field. The combobox is loaded with a collection of strings from a specified string array, and a reload
command updates the contents of the combobox from the array when the contents of array change.
#handle.ext
The #handle part of this item needs to be the same as the handle of the window containing the combobox.
The .ext part needs to be unique so that the program can send commands to the combobox and
get information from it later.
array$()
This is the name of the array (must be a string array) that contains the contents of the combobox. Be sure to
load the array with strings before opening the window. If some time later it becomes necessary to change
the contents of the combobox, simply change the contents of the array and send a RELOAD command to
the combobox. The index numbers of items in the array may not match the index numbers of the same
items in the control. The control is loaded from the array, and the first index used in the control is "1". No
empty strings are loaded into the control, so only array items that contain text are loaded.
eventHandler
This is the branch label or subroutine where execution begins when the user selects an item from the
combobox by clicking it. See also: Controls and Events
Example:
print #handle.ext, "font times_new_roman 10"
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
CommandLine$
Previous Top Next
CommandLine$
Description:
This special variable contains any switches that were added when Just BASIC was started. This is
especially useful in applications executing under the runtime engine. It allows a tokenized program to
receive information upon startup and act upon that information. The CommandLine$ variable can be
parsed in the same way as other strings to retrieve the information. One way to extract information from
the CommandLine$ is with INSTR() . The WORD$() and VAL() functions can also be used to evaluate the
contents of CommandLine$. See the examples and explanations below.
Usage:
In this example the program checks CommandLine$ for the existence of the word "red" and if it is there, the
program executes a color command:
'commandlinetest1.bas
'
'program to be tokenized
'to commandlinetest1.tkn
'and used with runtime engine
'commandlinetest1.exe
wait
[quit]
close #win : end
To call this program from another program as a TKN or EXE, or to run the EXE by using the RUN button in
Windows:
The CommandLine$ may be parsed using the WORD$() function as well. In the following example, the
program checks for three colors to use in a graphics window.
'commandlinetest2.bas
'
'program to be tokenized
'to commandlinetest2.tkn
'and used with runtime engine
'commandlinetest2.exe
[quit]
close #win : end
To call this program from another program as a TKN or EXE, or to run the EXE by using the RUN button in
Windows:
first$ = word$(CommandLine$,1)
firstval = val(first$)
UNREGISTERED VERSION
CONFIRM string; OF CHM TO PDF CONVERTER By THETA-SOFTWARE
responseVar
Description:
This statement opens a dialog box displaying the contents of string and presenting two buttons marked
'Yes' and 'No'. When the selection is made, the string "yes" is returned if the 'Yes' button is pressed, and
the string "no" is returned if the 'No' button is pressed by the user. The result is placed in responseVar.
Usage:
[quit]
Multiline Message
If line breaks are inserted into the message, it appears as a multiline message. Line breaks are
represented by chr$(13). The CONFIRM dialog window is sized to accomodate the message.
COS( n )
Description:
This function returns the cosine of the angle n. The angle n should be expressed in radians.
Usage:
for c = 1 to 45
print "The cosine of "; c; " is "; cos(c)
next c
Tip:
There are 2 * pi radians in a full circle of 360 degrees. A formula to convert degrees to radians is: radians =
degrees divided by 57.29577951
Description:
The DATA statement provides a convenient way to insert data into programs. The DATA can be read once
UNREGISTERED
or many timesVERSION OF CHM
using the READ TO PDF
statement. CONVERTER
A DATA By THETA-SOFTWARE
statement doesn't actually perform an action when it is
encountered in the program's code.
Example:
One or more DATA statements form the whole set of data elements. For example, the data represented in
the example above can also be listed in more than one DATA statement:
Error Handling
An attempt to read more DATA items than are contained in the DATA lists causes the program to halt with
an error. Notice that in the examples above, an "end" tag is placed in the DATA and when it is reached,
the program stops READing DATA. This is an excellent way to prevent errors from occuring. If an end tag
or flag of some sort is not used, be sure that other checks are in place to prevent the READ statement from
trying to access more DATA items than are contained in the DATA statements.
Description:
Instead of adopting the date$ variable from QBasic, Just BASIC uses a function instead. This approach
gives some additional flexibility. Unless otherwise indicated, the function returns today's date in the format
specified. See also TIME$( ) , Date and Time Functions
Usage:
d$ = date$( )
NOTE: All the above forms return a string except for date$("days"), and date$("4/1/02")
'some examples
print date$("4/1/02") 'this assumes 4/1/2002
print date$("1/1/1901")
print date$("April 1, 2002")
print date$("Apr 1, 2002")
Here is a small program that demonstrates the last two implementations of the date$ function. It determines
the number of shopping days until the holiday season:
today = date$("days")
target = date$("12/25/2003") 'subsititute current year and desired holiday
print "Shopping days left: ";
print target - today
DefaultDir$
Previous Top Next
Description:
A string variable that contains the default directory for the running Just BASIC program. The format is
UNREGISTERED VERSION
"drive:", or "drive:" OFisCHM
etc. There TO PDF
no backslash CONVERTER
appended By THETA-SOFTWARE
to the DefaultDir$ variable.
Usage:
print DefaultDir$
UNREGISTERED
As used with aVERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
FILES statement:
As used to access a text file in the same directory as the program. Notice that the backslash must be added
to the beginning of the filename:
Description:
DIM sets the maximum size of an array. Any array can be dimensioned to have as many elements as
memory allows. If an array is not DIMensioned explicitly, then the array will be limited to 11 elements, 0 to
10. Non DIMensioned double subscript arrays will be limited to 121 elements 0 to 10 by 0 to 10. The DIM
statement can be followed by a list of arrays to be dimensioned, separated by commas.
Usage:
'Example 1
print "Please enter 10 names."
for index = 0 to 10
input names$ : name$(index) = name$
next index
'Example 2
'Dimension three arrays at once
dim arrayOne(100), arrayTwo$(100, 5), arrayThree(100, 100)
The FOR . . . NEXT loop in the example above is limited to a maximum value of 10 because the array
names$( ) is not dimensioned, and therefore is limited to 11 elements, numbered 0 - 10. To remedy this
problem, add a DIM statement, as in the example below. Notice that it is not necessary to use all available
index numbers. In the example the array is filled beginning at index 1, ignoring index 0.
dim names$(20)
print "Please enter 20 names."
for index = 1 to 20
input names$ : names$(index) = name$
next index
dim customerInfo$(10, 5)
print "Please enter information for 10 customers."
for index = 0 to 9
input "Customer name >"; info$ : customerInfo$(index, 0) = info$
input "Address >"; info$ : customerInfo$(index, 1) = info$
input "City >"; info$ : customerInfo$(index, 2) = info$
input "State >"; info$ : customerInfo$(index, 3) = info$
input "Zip >"; info$ : customerInfo$(index, 4) = info$
next index
DisplayWidth
Previous Top Next
Description:
UNREGISTERED
The special VERSION OF CHMcontains
variable DisplayWidth TO PDFthe CONVERTER Byscreen
width of the display THETA-SOFTWARE
in pixels.
Description:
The special variable DisplayHeight contains the height of the display screen in pixels.
DO LOOP
Previous Top Next
do
'code in here
loop while booleanExpr
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
'execute the code inside this loop at least once
do
'code in here
loop until booleanExpr
UNREGISTERED
do while expr VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
'some code
loop
do until expr
'some code
loop
Description:
DO and LOOP cause code to be executed while a certain condition evaluates to true, or until a certain
condition evaluates to true. The "while" and "until" parts of this expression can be located either in the "DO"
statement or the "LOOP" statement. The following form is good for cases when you want a loop that always
executes once and then only loops back as long as a condition is met. It will continue looping back and
executing the code as long as the booleanExpr evaluates to true.
You can also use the UNTIL keyword to reverse the logic of the expression:
Usage:
'examples using "loop while" and "loop until"
print "print a zero"
do
print a
a = a + 1
loop while a > 10
print
end
Drives$
Previous Top Next
Description:
Drives$ is a system variable. It can be used like any other variable. Use it in expressions, print it, perform
UNREGISTERED
functions on it,VERSION OF CHM
etc. It is special in thatTO PDF CONVERTER
it contains ByallTHETA-SOFTWARE
the drive letters for the drives installed in the computer
in use.
For example:
print Drives$
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Will in many cases produce:
a: b: c:
input r$
[selectionMade]
close #win
end
DUMP
Previous Top Next
Description:
This statement forces anything that has been LPRINTed to be sent to the Print Manager to commence
printing immediately. If DUMP is not issued, the LPRINTed text will be printed, but it might not be printed
right away.
Usage:
Description:
This function is used to determine when reading from a sequential file whether the end of the file has been
UNREGISTERED VERSION
reached. If so, OFotherwise
-1 is returned, CHM TO PDF
0 is CONVERTER By THETA-SOFTWARE
returned.
Usage:
Description:
This statement is used to immediately terminate execution of a program. If any files or devices are still open
(see CLOSE ) when execution is terminated, then Just BASIC will close them and present a dialog
expressing this fact. It is good programming practice to close files and devices before terminating execution.
Note: The STOP statement is functionally identical to END and is interchangable. Also, make sure that
when a program is finished running that it terminates properly with an END statement. Otherwise the
program's windows may all be closed, giving the illusion that it has stopped running, but it will still be
resident in memory and may still consume processor resources.
Usage:
Description:
This command causes the program to exit a looping structure such as DO, FOR, WHILE. It also causes the
program to exit subs and functions.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
for i = 1 to 100
print i
if i > 7 then exit for
UNREGISTERED
next VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
call PrintHi 5
wait
function PrintThirdWord$(w$)
if word$(w$,3) = "" then
PrintThirdWord$ = "oops"
exit function
end if
PrintThirdWord$ = upper$(word$(w$,3))
end function
sub PrintHi n
if n > 10 then exit sub
for i = 1 to n
print "Hi"
next
end sub
EXP( n )
Previous Top Next
Description:
This function returns e ^ n, with e being 2.7182818 . . .
Usage:
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
FIELD is used with an OPEN "filename.ext" for random as #handle statement to specify the fields of data in
each record of the opened file. For example in this program FIELD sets up 6 fields of data, each with an
appropriate length, and associates each with a string variable that holds the data to be stored in that field:
open "custdata.001" for random as #cust len = 70 ' open as random access
UNREGISTERED VERSION
field #cust, 20 as name$, OF CHM
20 as TO15PDF
street$, CONVERTER
as city$, ByasTHETA-SOFTWARE
2 as state$, 10 zip$, 3 as age
[inputLoop]
input "Name >"; name$
input "Street >"; street$
input "City >"; city$
input "State >"; state$
input "Zip Code >"; zip$
input "Age >"; age
confirm "Is this entry correct?"; yesNo$ ' ask if the data is
' entered correctly
if yesNo$ = "no" then [inputLoop]
recNumber = recNumber + 1 ' add 1 to the record # and put the record
put #cust, recNumber
confirm "Enter more records?"; yesNo$ ' ask whether to enter more records
if yesNo$ = "yes" then [inputLoop]
Notice that Just BASIC permits the use of numeric variables in FIELD (eg. age), and it allows you to PUT
and GET with both string and numeric variables, automatically, without needing LSET, RSET, MKI$, MKS$,
MKD$, CVI, CVS, & CVD that are required with Microsoft BASICs.
Description:
This command opens a Windows Common Filedialog. Just BASIC uses long filenames and an explorer-
type filedialog. The dialog lets a user navigate around the directory structure, looking at filenames that have
a specific extension and selecting one.
titleString
This parameter is used to label the Filedialog window. It appears in the titlebar of the window. If the window
label specified has the word "save" in it, then the save style of the dialog will be used instead of the open
style. This means that the button to approve the file selection will say "save" rather than "open".
templateString
This parameter is used as a filter so that only files matching a wildcard are listed. To view all file types, the
templateString is " *.* " To access multiple extensions in a filedialog, separate the desired extensions with a
semicolon character, like this example, which displays files with extensions of both BAS and BAK files in the
dialog.
receiverVar$
When the user selects a filename, the resulting full path specification will be placed into receiverVar$. This
parameter contains an empty string if the user canceled the Filedialog.
UNREGISTERED
Usage VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
The following example produces a dialog box asking the user to select a text file to open:
If a file named "c:txt' was selected, and "Open" was clicked, then program execution would resume after
UNREGISTERED VERSION
placing the string "c:txt" intoOF CHM TO
fileName$. PDF
If on the CONVERTER Bywas
other hand "Cancel" THETA-SOFTWARE
clicked, then an empty string
would be placed into fileName$. Program execution would then resume. Be sure to trap this possibility in
your programs, or an error could occur.
if fileName$<>"" then
open fileName$ for input as #f
'do stuff
close #f
else
notice "No file chosen!"
end if
FILES
Previous Top Next
Description:
The FILES statement collects file and directory information from any disk and or directory and fills a double-
dimensioned array with the information. It is also good for determining if a specific file exists (see below).
Usage:
Knowing from info$(0, 0) how many files we have (call it n), we know that our subdirectory information starts
at n + 1, so:
You can optionally specify a wildcard. This lets you get a list of all *.ini files, for example. This is how you do
it:
This also makes it practical to use to check for file existence. If you want to know if a file c:bak exists, you
could try...
Description:
The FOR . . . NEXT looping construct provides a way to execute code a specific amount of times. See the
section below on the proper way to exit a loop before the counter variable reaches the limit. A starting and
UNREGISTERED VERSION
ending value are specified:OF CHM TO PDF CONVERTER By THETA-SOFTWARE
for var = 1 to 10
BASIC code
next var
UNREGISTERED VERSION
In this case, the OFis CHM
BASIC code TO10PDF
executed CONVERTER
times, with var being 1By
theTHETA-SOFTWARE
first time, 2 the second, and on
through 10 the tenth time. Optionally (and usually) var is used in some calculation(s) in the BASIC code. For
example if the BASIC code is print var ^ 2, then a list of squares for var will be displayed upon execution.
The specified range could just as easily be 2 TO 20, instead of 1 TO 10, but since the loop always counts +1
at a time, the first number must be less than the second. The way around this limitation is to place STEP n
at the end of for FOR statement:
This loops 19 times returning values for index that start with 20 and end with 2. STEP can be used with both
positive and and negative numbers and it is not limited to integer values. For example:
Incorrect:
for x = 0 to 1 step .01
print "The sine of "; x; " is "; sin(x)
next y
for index = 1 to 10
print "Enter Customer # "; index
input customer$
if customer$ = "" then [quitEntry] 1
'don't cut out of a for/next loop like this
cust$(index) = customer$
next index
[quitEntry]
index = 1
while customer$ <> "" and index <= 10
print "Enter Customer # "; index
input customer$
cust$(index) = customer$
index = index + 1
wend
EXIT FOR
If it is necessary to exit a loop before the counter variable has reached its final value, use the EXIT FOR
statement. This allows the program to exit the loop properly and to preserve the current value of the
counter variable. Use it like this:
for x = 1 to 20
y=x*3
if y>40 then EXIT FOR
next x
'Output
Final x value 14
Final y value 42
FUNCTION
Previous Top Next
Description:
This statement defines a function. The function can return a string value, or a numeric value. A function that
UNREGISTERED VERSION
returns a string value mustOFhaveCHM TOthat
a name PDF
endsCONVERTER By THETA-SOFTWARE
with the "$" character. A function that returns a numeric
value must not include a "$" in its name. Zero or more parameters may be passed into the function. A
function cannot contain another function definition, nor a subroutine definition. Note that the opening
parenthesis is actually part of the function name. Do not include a space between the name and the opening
parenthesis, or the code generates an error.
Right:
function functionName(var1, var2)
Wrong:
function functionName (var1, var2)
Returning a Value
To return a value from the function, assign the value to be returned to a variable of the same name as the
function. If no return value is specified, then numeric and string functions will return 0 and empty string
respectively.
functionName = returnValueExpression
Local Variables
The variable names inside a function are scoped locally, meaning that the value of any variable inside a
function is different from the value of a variable of the same name outside the function.
Passing by Reference
Variables passed as arguments into functions are passed "by value" which means that a copy of the variable
is passed into the function. The value of the variable is not changed in the main program if it is changed in
the function. A variable may instead by passed "byref" which means that a reference to the actual variable is
passed and a change in the value of this variable in the function changes the value of the variable in the
main program.
Arrays, structs and handles of files, DLLs and windows are global to a Just BASIC program, and visible
inside a function without needing to be passed in.
Special global status is given to certain default variables used for sizing, positioning, and coloring windows
and controls. These include variables WindowWidth, WindowHeight, UpperLeftX, UpperLeftY,
ForegroundColor$, BackgroundColor$, ListboxColor$, TextboxColor$, ComboboxColor$, TexteditorColor$.
The value of these variables, as well as DefaultDir$ and com can be seen and modified in any
subroutine/function.
Branch Labels
Branch labels are locally scoped. Code inside a function cannot see branch labels outside the subroutine,
and code outside a function cannot see branch labels inside any subroutine.
End Function
The function definition must end with the expression "end function."
Executing Functions
Be sure that a program doesn't accidentally flow into a function. A function should only execute when it is
called by command in the program.
wrong:
for i = 1 to 10
'do some stuff
next i
correct:
for i = 1 to 10
'do some stuff
next i
WAIT
Example Usage:
function wordCount(aString$)
index = 1
while word$(aString$, index) <> ""
index = index + 1
wend
wordCount = index - 1
end function
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
GET is used after a random access file is opened to get a record of information (see FIELD ) from a
specified position.
Usage:
print name$
print street$
print city$
print state$
print zip$
print age
close #cust
end
Description:
This statement specifies that the variables listed are global in scope. They are visible inside functions and
subroutines as well as in the main program code. Global variables can be modified inside functions and
subroutines as well, so care must be taken not to alter them accidentally, because this can easily cause
errors in the program that are difficult to isolate. Use global variables for things like values for true and false,
file paths, user preferences etc. See also: Function , Sub
Usage:
Special Globals
The special capitalized globals (like WindowWidth, DefaultDir$, the color setting variables, etc.) are global
variables. See the code below for examples of this.
Example one:
call makeWindow
print "WindowWidth was changed: "; WindowWidth
wait
sub makeWindow
if true <> false then
notice "Hey, true isn't the same as false. Whatta ya know?"
end if
WindowWidth = 350
texteditor #main.te1, 8, 8, 250, 152
textbox #main.tb1, 16, 192, 112, 24
statictext #main.Statictext4, "Font_Name w h", 8, 168, 100, 18
button #main.apply1, "Apply", [applyFont1], UL, 136, 192, 67, 24
radiobutton #main.rb1, "Radiobutton 1", [set], [clear], 16, 226, 190, 20
checkbox #main.cb1, "Checkbox 1", [set], [clear], 16, 256, 190, 20
open "Untitled" for window as #main
#main "font "; font$
#main.te1 "The font is: "; font$
end sub
Example two:
'define a global string variable:
global title$
title$ = "Great Program!"
UNREGISTERED
sub openItVERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
statictext #it.stext, "Look Mom!", 10, 10, 70, 24
textbox #it.tbox, 90, 10, 200, 24
open title$ for window as #it
print #it.tbox, "No hands!"
end sub
GOSUB label
Previous Top Next
Description:
GOSUB causes execution to proceed to the program code following the label using the form 'GOSUB
label'. The label can be either a traditional line number or a branch label name enclosed in square
brackets, like this: [branchLabel]. Spaces and numbers are not allowed as part of branch label names..
After execution is transferred to the point of the branch label, then each statement will be executed in
normal fashion until a RETURN is encountered. When this happens, execution is transferred back to the
statement immediately after the GOSUB. The section of code between a GOSUB and its RETURN is
known as a 'subroutine.' One purpose of a subroutine is to save memory by having only one copy of
code that is used many times throughout a program.
Usage:
[yesOrNo]
input answer$
answer$ = left$(answer$, 1)
if answer$ = "y" then answer$ = "Y"
if answer$ = "n" then answer$ = "N"
if answer$ = "Y" or answer$ = "N" then return
print "Please answer Y or N."
goto [yesOrNo]
Using GOSUB [yesOrNo] in this case saves many lines of code in this example. The subroutine
[yesOrNo] could easily be used many other times in such a hypothetical program, saving memory and
reducing typing time and effort. This reduces errors and increases productivity.
Description:
GOTO causes Just BASIC to proceed to the program code following the label, using the form 'GOTO label'.
UNREGISTERED
The label canVERSION OF CHM
be either a traditional TO
line PDF or
number CONVERTER
a branch label inBy
theTHETA-SOFTWARE
format [branchLabel] where the
branch label name can be any upper/lowercase letter combination. Spaces and digits are not allowed.
UNREGISTERED
Usage: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
.
.
[repeat]
.
.
[askAgain]
print "Make your selection (m, r, x)."
input selection$
if selection$ = "M" then goto [menu]
if selection$ = "R" then goto [repeat]
if selection$ = "X" then goto [exit]
goto [askAgain]
.
.
[menu]
print "Here is the main menu."
.
.
[exit]
print "Okay, bye."
end
Notes:
Description:
The graphicbox is a control that can be added to any window type. It understands all of the commands of
that are used in a window of type "graphics."
#handle.ext
The #handle part must be the same as the window that will contain the graphicbox. The .ext part must be
unique for the graphicbox.
It should be noted that graphics windows and graphicboxes are intended for drawing graphics. It is not
advisable to place controls within them, since some controls do not work properly when placed in
graphicboxes or graphics windows. If there is a need for text display within a graphicbox or graphics
window, use the graphics text capabilities rather than a statictext control.
GRAPHICBOX COMMANDS
The following commands are sent to a graphicbox. When a graphicbox is disabled, it can no longer capture
keyboard and mouse events.
Description:
This command adds a groupbox to a window or dialog box. Other controls added to the owning window
which overlap the displayed area of the groupbox will be nested inside the groupbox. This is particularly
useful for radiobuttons. It is possible for only one radiobutton in a radio-set to be "set" at one time. The
groupbox allows the window to have multiple radio-sets of radiobuttons. Only one of all radiobuttons in a
groupbox will be allowed to be in a set state. Click on one to set it, and all the others will be reset.
#handle.ext
This must be the same #handle as the window that contains the groupbox. ".ext" is an optional unique
extension unique to the groupbox.
"label"
This is the caption or text label that appears on the groupbox.
x, y
These parameters determine where to position the groupbox relative to the upper left corner of the window
workspace.
wide, high
These parameters specify how wide and high the groupbox will be in pixels.
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
Example:
print #handle.ext, "!font times_new_roman 10"
print #handle.ext, "!enable"
This causes the control to be enabled.
Description:
The IF...THEN statement provides a way to change program flow based on a test expression. For example,
the following line directs program execution to branch label [soundAlarm] if fuel runs low.
Since the expression after THEN is a branch label, this command may also be written using the GOTO
statement instead of the THEN statement.
Any time the statement after THEN is a branch label, you may use GOTO instead of THEN.
Another way to control program flow is to use the IF...THEN...ELSE statement. This extended form of
IF...THEN adds expressiveness and simplifies coding of some logical decision-making software. Here is an
example of its usefulness.
Consider:
[retry]
input "Please choose mode, (N)ovice or e(X)pert?"; mode$
if len(mode$) = 0 then print "Invalid entry! Retry" : goto [retry]
mode$ = left$(mode$, 1)
if instr("NnXx", mode$) = 0 then print "Invalid entry! Retry" : goto [retry]
if instr("Nn", mode$) > 0 then print "Novice mode" : goto [main]
print "eXpert mode"
[main]
print "Main Selection Menu"
Any number of variations on these formats are permissible. The (a < b) BOOLEAN expression is of course
only a simple example chosen for convenience. It must be replaced with the correct expression to suit the
problem.
IF...THEN...END IF is another form using what are called conditional blocks. This allows great control over
the flow of program decision making. Here is an example of code using blocks.
if qtySubdirs = 0 then
print "None."
goto [noSubs]
end if
A block is merely one or more lines of code that are executed as a result of a conditional test. There is one
block in the example above, and it is executed if qtySubdirs = 0.
if qtySubdirs = 0 then
print "None."
else
print "Count of subdirectories: "; qtySubdirs
end if
This type of coding is easy to read and understand. There are two blocks in this example. One is executed if
qtySubdirs = 0, and one is executed if qtySubdirs is not equal to 0. Only one of the two blocks will be
executed (never both as a result of the same test).
if verbose = 1 then
if qtySubdirs = 0 then
print "None."
else
print "Count of subdirectories: "; qtySubdirs
end if
end if
In the example above, if the verbose flag is set to 1 (true), then display something, or else skip the display
code entirely.
Keyboard input can only be trapped in graphics windows or graphicboxes. When a key is pressed, the
information is stored in the variable Inkey$
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This special variable holds either a single typed character or multiple characters including a Windows virtual
keycode. Notice that because Inkey$ is a variable, it is case sensitive. Remember that at this time, only the
graphics window and graphicbox controls can scan for keyboard input. The virtual keycodes are standard
Windows constants, and include arrow keys, function keys, the ALT, SHIFT, and CTRL keys, etc.
UNREGISTERED VERSION
If Inkey$ is a single OF that
character, CHM TO PDF
character CONVERTER
will be BySee
the key pressed. THETA-SOFTWARE
the section below for a description
of Inkey$ when len(Inkey$) is greater than 1.
[mainLoop]
print #graph, "setfocus"
input r$
key$ = Inkey$
if len(key$) = 1 then
notice key$+" was pressed!"
else
keyValue = asc(right$(key$, 1))
if keyValue = _VK_SHIFT then
notice "Shift was pressed"
else
if keyValue = _VK_CONTROL then
notice "Ctrl was pressed"
else
notice "Unhandled key pressed"
end if
end if
end if
WAIT
Shift = 4
Ctrl = 8
Alt = 16
They can be used in any combination. If Inkey$ contains more than one character, you can check to see
which (if any) of the three special keys was also pressed by using the bitwise AND operator. If shift alone
was pressed, then the ASCII value of the first character will be 4. If Shift and Alt were both pressed, then
the ASCII value of the first character will be 20, and so on. Special keys trigger a new value for Inkey$ when
they are pressed and again when they are released. Here is an example that uses bitwise AND to
determine which special keys were pressed.
wait
[check]
shift=4
ctrl=8
alt=16
a=asc(left$(Inkey$,1))
if len(Inkey$)>1 then
m$=""
wait
[quit]
close #1:end
See also, Using virtual key constants with Inkey$ , Using Inkey$ , Reading Mouse Events and Keystrokes .
INPUT
Previous Top Next
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command has several possible forms:
input var
This form causes a program to stop and wait for user to enter data in the program's mainwin and press the
'Return' key. It will then assign the data entered to var.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
input "enter data"; var
This form will display the string "enter data" and then stop and wait for user to enter data in the program's
mainwin and press 'Return'. It will then assign the data entered to var.
Usage:
Arrays
t is possible to use Input and Line Input to fill arrays directly. To input directly to an array:
input array$(x)
Question Mark
Most versions of Microsoft BASIC implement INPUT to automatically place a question mark on the display in
front of the cursor when the user is prompted for information:
produces:
produces:
and:
input limit
produces simply:
?|
In the simple form input limit, the question mark is inserted automatically, but if a prompt is specified, as in
the above example, only the contents of the prompt are displayed, and nothing more. If it is necessary to
obtain input without a prompt and without a question mark, then the following will achieve the desired effect:
Additionally, in most Microsoft BASICs, if INPUT expects a numeric value and a non numeric or string value
is entered, the user will be faced with a comment something like 'Redo From Start', and be expected to
reenter. Just BASIC does not automatically do this, but converts the entry to a zero value and sets the
variable accordingly.
INPUT$(#handle, items)
UNREGISTERED
Description:VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This permits the retrieval of a specified number of items from an open file or device using #handle. If
#handle does not refer to an open file or device then an error will be reported. It can also be used to read
a character at a time from the mainwindow (see example below).
Usage:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
'read and display a file one character at a time
open "c:bat" for input as #1
[loop]
if eof(#1) <> 0 then [quit]
print input$(#1, 1);
goto [loop]
[quit]
close #1
end
For most devices (unlike disk files), one item does not refer a single character, but INPUT$( ) may return
items more than one character in length. In most cases, use of INPUT #handle, varName works just as
well or better for reading devices.
while EOF(#handle)=0
input #handle, array$(total)
total=total+1
wend
close #handle
for i = 0 to total
print array$(i)
next
UNREGISTERED
Description:VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function returns the position of string2 within string1. If string2 occurs more than once in string1,
then only the position of the leftmost occurance will be returned. If the starting parameter is included,
then the search for string2 will begin at the position specified by starting.
Usage:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
print instr("hello there", "lo")
produces: 4
If string2 is not found in string1, or if string2 is not found after starting, then INSTR( ) will return 0.
and so does:
Description:
This function removes the fractional part of "n" (a number), leaving only the whole number part behind. The
fractional part is the part of the number after the decimal point.
Usage:
[retry]
input "Enter an integer number>"; i
if i<>int(i) then bell: print i; " isn't an integer! Re-enter.": goto [retry]
KILL s$
Previous Top Next
KILL "filename.ext"
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command deletes the file specified by filename.ext. The filename can include a complete path
specification.
LEFT$(string, number)
Description:
This function returns from the string, string variable, or string expression string the specified number of
characters starting from the left. If string is "hello there", and number is 5, then "hello" is the result.
Usage:
[retry]
input "Please enter a sentence>"; sentence$
if sentence$ = "" then [retry]
for i = 1 to len(sentence$)
print left$(sentence$, i)
next i
Produces:
Note: If number is zero or less, then "" (an empty string) will be returned. If number is greater than or
equal to the number of characters in string, then string will be returned.
LEN( string )
LEN( structName.struct )
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Description:
This function returns the length in characters of string, which can be any valid string expression. It also
returns the size of a struct.
Usage:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
prompt "What is your name?"; yourName$
print "Your name is "; len(yourName$); " letters long"
Description:
LET is an optional prefix for any BASIC assignment expression. Most programmers leave the word out of
their programs, but some prefer to use it.
Usage:
Either is acceptable:
Another example:
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This gets the next data line from the open file or device using handle #handle and assigns the data to var$.
If no device or file exists that uses the handle named #handle, then it returns an error. The line input
statement reads from the file, ignoring commas in the input stream and completing the data item only at the
next carriage return or at the end of file. This is useful for reading text with embedded commas
UNREGISTERED
Usage: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Arrays:
Line Input now allows input directly multiple variables and arrays.
filedialog "Open","*.txt",file$
if file$="" then end
dim a$(3000)
while not(eof(#f))
line input #f, a$(i)
i=i+1
wend
close #f
for j=0 to i
print a$(j)
next
end
Description:
Listboxes are added to windows to provide a list selection capability in programs. The listbox is loaded with
a collection of strings from a specified string array, and a RELOAD command updates the contents of the
listbox from the array when the contents of the array change.
#handle.ext
The #handle part of this statement must be the same as the #handle of the window that contains the listbox.
The ".ext" part must be unique so that the program can send commands to the listbox and get information
from it later.
array$()
This is the name of the array (must be a string array) that contains the contents of the listbox. Be sure to
load the array with strings before opening the window. If some time later it is necessary to change the
contents of the listbox, simply change the contents of the array and send a RELOAD command. The index
numbers of items in the array may not match the index numbers of the same items in the control. The
control is loaded from the array, and the first index used in the control is "1". No empty strings are loaded
into the control, so only array items that contain text are loaded.
eventHandler
This is the branch label or subroutine where execution begins when the user selects an item from the listbox
by double-clicking. Selection by only single clicking does not cause branching to occur unless a
"singleclickselect" command is issued to the listbox. See also: Controls and Events
x, y
This is the distance in x and y (in pixels) of the listbox from the upper-left corner of the window.
wide, high
This specifies the width and height (in pixels) of the listbox.
Example:
print #handle.ext, "font times_new_roman 10"
Sample Program
[selectionMade]
print #status.list, "selection? selection$"
notice selection$ + " was chosen"
close #status
end
[cancelStatusSelection]
notice "Status selection cancelled"
close #status
end
Control of the listbox in the sample program above is provided by printing commands to the listbox, just as
with general window types in Just BASIC. The listbox has the handle #status.list, so to find out what was
selected, use the statement print #status.list, "selection? selection$". If the result is a string of length zero (a
null string), this means that there is no item selected.
wait
[cancelStatusSelection]
notice "Status selection cancelled"
close #status
end
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
LOADBMP
Previous Top Next
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Loads a standard Windows *.BMP bitmap file on disk into Just BASIC. The "name" is a string chosen to
describe the bitmap being loaded and the "filename.bmp" is the actual name of the bitmap disk file. Once
loaded, the bitmap can then be displayed in a graphics window type using the DRAWBMP command (see
Graphics Window Commands ).
UNREGISTERED
Usage: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
loadbmp "copyimage", "bmpbmp"
open "Drawbmp Test" for graphics as #main
print #main, "drawbmp copyimage 10 10"
wait
LOCATE IN MAINWINDOW
locate x, y
Description:
Using LOCATE in the mainwin causes text to be printed at the x, y location specified. These coordinates
refer to the column and row of text, not to screen pixels. This command functions in the same was as the
Qbasic LOCATE command and is used to position text on the mainwin. Here is a short demo:
'plot a wave
for x = 1 to 50
i = i + 0.15
locate x, 12 + int(cos(i)*10)
print "*";
next x
LOC( #h )
Previous Top Next
LOC( #handle )
Description:
UNREGISTERED VERSION
The LOC( #handle OF retrieves
) function CHM TO thePDF CONVERTER
current By pointer
position of the file THETA-SOFTWARE
when a file whose handle is
specified has been opened for BINARY access. The current position of the file pointer is used when
reading or writing data to a binary file. See also: SEEK
Usage:
LOF(#handle)
Description:
This function returns the number of bytes contained in the open file referenced by #handle.
Usage:
Description:
This function returns the natural logarithm of n.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
LOWER$(s$)
Description:
This function returns a copy of the contents of the string, string variable, or string expression s$, but with all
letters converted to lowercase.
Usage:
Produces:
LPRINT expr
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This statement is used to send data to the default printer (as determined by the Windows Print Manager). A
series of expressions can follow LPRINT (there does not need to be any expression at all), each separated
by a semicolon. Each expression is sent in sequence. Printing can be formatted into columns with the
TAB(n) function. When you are finished sending data to the printer, you should commit the print job by using
the DUMP statement. Just BASIC will eventually send your print job, but DUMP forces the job to finish.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
age = 23
lprint "Ed is "; age; " years old"
'This prints Ed is 23 years old
dump
Description:
This sets the width or width and height of a program's main window. This is specified in colums and rows of
text according the font of the mainwindow. This statement is usually placed at the beginning of the program
code.
Usage:
or...
UNREGISTERED VERSION
MENU #handle, OF[branchLabel],
"title", "text", CHM TO PDF CONVERTER
"text2", [branchLabel2],By| THETA-SOFTWARE
,...
or
MENU #handle, "title", "text", subName1, "text2", subName2, |, ...
Description:
This command adds a pull down menu to the window at #handle. The item "title" specifies the title of the
menu, as seen on the menu bar of the window, and each "text", [branchLabel] pair after the title adds a
menu item to the menu, and tells Just BASIC where to branch to when the menu item is chosen. A sub can
be used as a menu event handler.
The " | " character can optionally be placed between menu items, to cause a separating line to be added
between the items when the menu is pulled down.
The " & " character placed in the title and text items for the menu specifies the accelerator placement for
each item. The letter directly following the " & " character will act as a hotkey for that menu item, when it is
pressed while the user presses and holds down the ALT key. The hotkey appears underlined in the menu
display.
The menu command must be contained on one line. To break the line for viewing in the Just BASIC editor,
use the line continuation character , " _ ".
Usage:
Notice that the MENU commands must go before the OPEN statement, and must use the same handle as
the window (#geo in this case.
sub two
notice "Two!"
end sub
Textboxes and texteditors cause an automatic EDIT menu to be added to the menu bar. To locate this
automatic menu, use the menu command with a menu name of "edit" and no items. Do not include the " & "
character in this dummy "edit" menu title. If the location for the automatic "edit" menu is not specified, it will
appear at the right end of the menu bar. Do not attempt to replace the automatic "edit" menu with one of
your own, or it will not function properly.
Example, locate the edit menu in the second position on the menu bar:
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function permits the extraction of a sequence of characters from the string, string variable, or string
expression string starting at index. [number] is optional. If number is not specified, then all the characters
from index to the end of the string are returned. If number is specified, then only as many characters as
number specifies will be returned, starting from index.
UNREGISTERED
Usage: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Produces:
Earth
And:
string$ = "The quick brown fox jumped over the lazy dog"
for i = 1 to len(string$) step 5
print mid$(string$, i, 5)
next i
Produces:
The_q
uick_
brown
_fox_
jumpe_
d_ove
r_the
_lazy
_dog
Note:
var = MIDIPOS( )
Description:
This function returns the current position of play in a file being played with PLAYMIDI.
Description:
The MKDIR( ) function attempts to create the directory specified. If the directory creation is successful the
UNREGISTERED
returned valueVERSION OF CHM
is 0. If the directory TO PDF
creation CONVERTER
was unsuccessful, By THETA-SOFTWARE
a value indicating a DOS error is returned.
Usage:
MOD
num1 MOD num2
Description:
The MOD command returns the remainder when num1 is divided by num2.
Usage:
'produces
3
11
When 15 is divided by 4, the quotient is 3, with a remainder of 3. MOD returns that remainder. When 27 is
divided by 16, the quotient is 1, with a remainder of 11. MOD returns that remainder.
NAME a$ AS b$
Previous Top Next
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command renames the file specified in the string expression StringExpr1 to StringExpr2. StringExpr1
can represent any valid filename that is not a read-only file, and StringExpr2 can be any valid filename as
long as it doesn't specify a file that already exists.
Usage:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
'rename the old file as a backup
name rootFileName$ + ".fre" as rootFileName$ + ".bak"
'open a new file and write data
open rootFileName$ + ".fre" for output as #disk
NOMAINWIN
Previous Top Next
Description:
This command instructs Just BASIC not to open a main window (the mainwin) for the program that includes
this statement. Some simple programs which do not use separate windows for graphics or text may use only
the mainwin. Other programs may not need the mainwin to do their thing. If the mainwin is not needed,
including NOMAINWIN somewhere in the program source code prevents the window from opening.
If NOMAINWIN is used, when all other windows owned by that program are closed, then the program
terminates execution automatically.
It is often better to place a NOMAINWIN statement in a program after it is completed and debugged, so that
you can easily terminate an errant program just by closing its mainwin.
Usage:
NOMAINWIN
Open "Test" for window as #win
wait
NOTICE
Previous Top Next
UNREGISTERED VERSION
NOTICE "string OF CHM TO PDF CONVERTER By THETA-SOFTWARE
expression"
Description:
This command pops up a dialog box which displays "string expression" and includes an OK button, which
the user presses after the message is read. Pressing the ENTER key also closes the notice dialog box.
"string expression"
Two forms are allowed. If "string expression" has no carriage return character (ASCII 13), then the title of
the dialog box is 'Notice' and "string expression" is the message displayed inside the dialog box. If "string
expression" does have a Chr$(13), then the part of "string expression" before Chr$(13) is used as the title for
the dialog box, and the part of "string expression" after Chr$(13) is displayed as the message inside. Further
Chr$(13) will force line breaks into the text contained in the message.
Usage:
Or:
Description:
Several of the QBasic error codes are supported, but some are not relevant, and there are some new ones.
When an error occurs, the special variables Err and Err$ hold numeric and string values describing what sort
of error happened. Some kinds of errors do not have a numeric value, in which case Err will be zero.
If an error occurs in a user function or subroutine, Just BASIC will exit the current function or subroutine and
continue to exit functions and subroutines until it finds ON ERROR handler.
Usage:
end
[errorHandler]
print "Error string is " + chr$(34) + Err$ + chr$(34)
print "Error number is ";Err
end
Error string is "OS Error: The system cannot find the file specified."
Error number is 53
ONCOMERROR
Previous Top Next
ONCOMERROR [branchLabel]
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This sets or clears a branch label for handling errors when doing serial communications.
UNREGISTERED VERSION
'to disable com OF CHM
error TO PDF CONVERTER By THETA-SOFTWARE
handling
oncomerror
Usage:
'open com2
open "COM2:9600,n,8,1" for random as #1
[handleIt]
'close com2
close #1
end
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
The OPEN command opens communication with a device, which can be a disk file, a window, or a serial
communications port. The command must be told what to open, for what purpose, and a descriptive, unique
name or "handle" must be assigned to it so that other functions can access the open device. Handles must
always begin with "#" to identify them as such and to distinguish them from other variables. The details for
using the OPEN statement are shown below. It will be necessary to refer to the individual topics for complete
UNREGISTERED VERSION
explanations for using OPENOFwithCHM TO PDF
the various CONVERTER By THETA-SOFTWARE
devices.
Note: Any device that is opened during the normal operation of the program must be closed before program
execution is finished. See CLOSE
device
file
If the device to be opened is a file, the device parameter must be a valid disk filename. This may be
expressed as a string variable , or as a literal text expression enclosed in quotes. For more on coding file
specifications, see Path and Filename .
purpose
Files may be opened for the purpose of INPUT, OUTPUT, APPEND, RANDOM or BINARY access. The
final LEN=n parameter applies to files opened for RANDOM access. For more on opening files, please
see File Operations .
usage:
open "c:txt" for input as #f
window
If the device to be opened is a window, the device parameter will become the caption of the window. The
caption is the text contained on the titlebar of the window.
purpose
When the device is a window, the purpose parameter is the window type. There are many possibilities
for window types and these are explained in: Window Types , Window and Dialog Commands ,
Graphical User Interface .
usage:
open "My Cool Program" for window_nf as #main
Usage:
To open com port 2 at 9600 baud, 8 data bits, 1 stop bit, and no parity, use this line of code:
open "com2:9600,n,8,1" for random as #commHandle
#handle
The #handle is a unique name given to the device so that it can be accessed by functions in the program.
Use a descriptive word for the handle. It must start with a # and may contain any alpha-numeric characters,
but no spaces. This special handle is used to identify the open device in later program statements. Some
possible handles are as follows:
#commHandle
#newfile
#main
#win
#2
OPEN "COMn:..."
Previous Top Next
Description:
UNREGISTERED VERSION
The OPEN "COMn:" OF CHM
statement opens TO PDF
a serial CONVERTER
communications portBy
for THETA-SOFTWARE
reading and writing. This feature
uses Microsoft Windows' own built-in communications API, so if you have a multiport communications card
and a WIndows driver to support that card, you should be able to use any port on the card.
75 110 150 300 600 1200 2400 1800 2400 4800 9600 19200 38400 57600 115200
N No parity
E Even parity
O Odd parity
S Space parity
M Mark parity
5 bits long
6 bits long
7 bits long
8 bits long
1 stop bit
2 stop bits
Additional optional parameters can be included after the baud, parity, data and stop information:
Other defaults:
To set the in and out communications buffers (each port has its own), set the variable Com (notice the
uppercase C) to the desired size before opening the port. Changing the variable after opening a port does
not affect the size of the buffers for that port while it is open.
'set the size of the communications buffers
'(in and out) to 16K each
Com = 16384
Usage Notes:
To open com port 2 at 9600 baud, 8 data bits, 1 stop bit, and no parity, use this line of code:
It is recommended that you set certain handshaking switches so that your program doesn't just freeze when
waiting for data to come in or trying to send data. To do this, we add ds0, cs0, and rs switches as below.
You needs may differ, but these work well for most applications. Notice we use a different communications
speed in this example.
Remember that when a modem dials and connects to another modem, it negotiates a cpnnectopm speed.
In the case of 14400 speed modems, you need to specify 19200 as the connection speed and let the
modems work it out between themselves during the connect. This is because 14400 is not a baud rate
supported by Windows (and you'll find that QBASIC doesn't directly support 14400 baud either).
Once the port is open, sending data is accomplished by printing to the port (ATZ resets modems that
understand the Hayes command set):
To read from the port you should first check to see if there is anything to read. This is accomplished in this
fashion:
numBytes = lof(#commHandle)
Putting the lof( ) and input$( ) functions together on one line, it looks like this:
close #commHandle
Just BASIC has the ability to disable DSR checking by specifying a zero or non value using the DS switch:
or
Use the txcount(#handle) function to get a count of bytes in a serial communications transmit queue.
count = txcount(#com)
Description:
This variable holds the string "Windows.
Description:
UNREGISTERED VERSION
This plays a *.MIDI OF CHM
sound from TO
a file on PDF
disk CONVERTER
as specified ByThe
in filename. THETA-SOFTWARE
length variable will hold the length
of the MIDI file (not in seconds). You can only play one file at a time. Periodically, you will need to use the
MIDIPOS( ) function to see if you've reached the end of the music:
Finally, use the STOPMIDI command to close the music file before you can play a different one.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
[checkPlay]
if howLong = midipos( ) then [musicEnded]
wait
[musicEnded]
stopmidi
timer 0
wait
Description:
This plays a *.wav sound from a file on disk as specified in filename. If mode is specified, it must be one of
the modes described below:
sync (or synch) - wait for the wave file to finish playing (the default)
async (or asynch) - don't wait for the wave file to finish playing
loop - play the wave file over and over (cancel with: playwave "")
Usage
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This statement is used to send data to the mainwin, to a disk file, or to other windows. A series of
expressions can follow PRINT, each separated by a semicolon. Each expression is displayed in sequence.
If the data is being sent to a disk file, or to a window, then #handle must be present.
Usage:
age = 23
print "Ed is "; age; " years old"
'produces: Ed is 23 years old
When sending data to a disk file and in regard to the use of the semicolon at the end of the expression list,
the rules are similar, although the result is not displayed on the screen. Use of a semicolon at the end of a
line suppresses the carriage return/line feed that causes text to be printed on the next line. When printing to
a window, the expressions sent are usually commands to the window (or requests for information from the
window). For more information, see GUI Programming .
PrinterFont$
Previous Top Next
PrinterFont$ = fontSpec
Description:
You can set the font used for LPRINTing text to the printer. The format used for specifying the font is the
same as for specifying the font in a graphics window. See also How to Specify Fonts , LPRINT .
The last font set before a page is printed is used for all the text on that page.
Usage:
UNREGISTERED VERSION
PROMPT "string OFresponseVar$
expression"; CHM TO PDF CONVERTER By THETA-SOFTWARE
Description:
The PROMPT statement opens a dialog box, displays the message contained in "string expression", and
waits for the user to type a response in the textbox and press the ENTER key, or press the OK or Cancel
button on the dialog. The entered information is placed in responseVar$. If Cancel is pressed, then a string
of zero length is returned. If responseVar$ is set to some string value before PROMPT is executed, then
that value will become the "default" or suggested response that is displayed in the textbox contained in the
PROMPT dialog. This means that when the dialog is opened, the contents of responseVar$ will already be
entered as a response for the user, who then has the option to either type over that 'default' response, or to
press 'Return' and accept it.
response$ = "C:"
prompt "Search on which Drive? A:, B:, or C:"; response$
[testResponse]
if response$ = "" then [cancelSearch]
if len(response$) = 2 and instr("A:B:C:", response$) > 0 then [search]
response$="C:"
prompt "Unacceptable response. Please try again. A:, B:, or C:"; response$
goto [testResponse]
[search]
print "Starting search . . . "
Specify a Caption:
response$ = "C:"
prompt "Please Specify" + chr$(13) + "Search on which Drive? A:, B:, or C:"; response$
.
.
PUT #h, n
Previous Top Next
PUT #handle, n
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
PUT is used after a random access file is opened to place a record of information (see FIELD ) into the file
#handle at the record numbered n. For example:
close #cust
end
Description
This command adds a radiobutton control to the window referenced by #handle. Radiobuttons have two
states, set and reset. They are useful for getting input of on/off type information.
All radiobuttons on a given window are linked together, so that if one is set by clicking on it, all the others will
be reset (cleared). The exception to this rule occurs when radiobuttons are placed within the confines of
groupboxes. In this case, only radiobuttons contained within the same groupbox act as a radio-set. Clicking
(setting) a radiobutton within one groupbox has no effect on radiobuttons that are placed within other
groupboxes. See the demo below.
#handle.ext
This specifies handle for this control. The #handle part must be the same as the #handle of the window that
contains the radiobutton, and the ".ext" part names the radiobutton uniquely in the window.
"label"
This specifies the visible text of the radiobutton
setHandler
This is the branch label or subroutine executed by the program when the user sets the radiobutton by
clicking on it. See also: Controls and Events
resetHandler
This is the branch label or subroutine executed when the user resets the radiobutton by clicking on it. (this
doesn't actually do anything because radiobuttons can't be reset by clicking on them).
xOrigin
This is the x position of the radiobutton relative to the upper left corner of the window it belongs to.
yOrigin
This is the y position of the radiobutton relative to the upper left corner of the window it belongs to.
width
This is the width of the radiobutton control
height
This is the height of the radiobutton control
Example:
print #handle.ext, "font times_new_roman 10"
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
print #handle.ext, "enable"
This causes the control to be enabled.
Usage:
WindowWidth = 520
WindowHeight = 220
[inputLoop]
wait
[alwaysConfirm]
status$ = "Always Confirm"
wait
[whenReplacingConfirm]
status$ = "When Replacing Confirm"
wait
[neverConfirm]
status$ = "Never Confirm"
wait
[alwaysClose]
cstatus$ = "Always Close"
wait
[whenReplacingClose]
cstatus$ = "When Replacing Close"
wait
[neverClose]
cstatus$ = "Never Close"
wait
[cfgOk]
msg$ = status$ + chr$(13) + cstatus$ + chr$(13)
[nil]
wait
For information on creating controls with different background colors, see Colors and the Graphical User
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Interface .
RANDOMIZE
Previous Top Next
RANDOMIZE n
Description:
This function seeds the random number generator in a predictable way. The seed numbers must be greater
than 0 and less than 1. Numbers such as 0.01 and 0.95 are used with RANDOMIZE.
Usage:
Description:
This fetches the next strings and/or numeric values from DATA statements in a program. The READ
UNREGISTERED
statement willVERSION
fetch enoughOF CHM
items to fillTO
the PDF CONVERTER
variable By THETA-SOFTWARE
names the programmer specifies. The values fetched
will be converted to fit the variables listed (string or numeric). Do not attempt to READ DATA directly into
arrays. READ into variables, then assign the value in the variable to an element in the array.
Example:
UNREGISTERED VERSION
'read the numbers OF
andCHM TOdescriptions
their PDF CONVERTER By THETA-SOFTWARE
while desc$ <> "end"
read desc$, value
print desc$; " is the name for "; value
wend
'here is our data
data "one hundred", 100, "two", 2, "three", 3, "end", 0
end
Error Handling
If you try to read more DATA items than are contained in the DATA lists, the program will halt with an
error. Notice that in the examples above, an "end" tag is placed in the DATA and when it is reached, the
program stops READing DATA. This is an excellent way to prevent errors from occurring. If an end tag or
flag of some sort is not used, be sure that other checks are in place to prevent the READ statement from
trying to access more DATA items than are contained in the DATA statements.
READJOYSTICK 1
or
READJOYSTICK 2
Description:
You can read the position of up to two joysticks and their buttons. The readjoystick command reads the x, y,
and z of an installed joystick (proper drivers must also be installed) and also their buttons. The variables are
visible everywhere because they are global.
Usage:
readjoystick 1
The command above reads the current status of joystick 1 and places the values into these global variables:
readjoystick 2
The command above reads the current status of joystick 2 and places the values into these global variables:
Description:
This redimensions an already dimensioned array and clears all elements to zero (or to an empty string in the
UNREGISTERED
case of string VERSION
arrays). ThisOF
canCHM
be veryTO PDFforCONVERTER
useful Bythat
writing applications THETA-SOFTWARE
have data sets of unknown size.
If you dimension arrays that are extra large to make sure you can hold data, but only have a small set of
data, then all the space you reserved is wasted. This hurts performance, because memory is set aside for
the number of elements in the DIM statement.
Usage:
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
dim cust$(10) 'dimension the array
.
.
.
'now we know there are 510 customers on file
redim cust$(510)
'now read in the customer records
REM
Previous Top Next
REM comment
Description:
The REM statement is used to place comments inside code to clearly explain the purpose of each section of
code. This is useful to both the programmer who writes the code or to anyone who might later need to
modify the program. Use REM statements liberally. There is a shorthand way of using REM, which is to use
the ' (apostrophe) character in place of the word REM. This is cleaner to look at, but you can use whichever
you prefer. Unlike other BASIC statements, with REM you cannot add another statement after it on the
same line using a colon ( : ) to separate the statements. The rest of the line becomes part of the REM
statement.
Usage:
rem let's pretend that this is a comment for the next line
print "The mean average is "; meanAverage
Or:
' let's pretend that this is a comment for the next line
print "The strength of the quake was "; magnitude
rem thank the user : print "Thank you for using Super Stats!"
(even the print statement becomes part of the REM statement)
Note:
When using ' instead of REM at the end of a line, the statement separator : (colon) is not required to
separate the statement on that line from its comment.
For example:
print "Total dollar value: "; dollarValue : rem print the dollar value
print "Total dollar value: "; dollarValue ' print the dollar value
RESTORE
RESTORE [branchLabel]
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Description:
RESTORE will reset the reading of DATA statements so that the next READ will get information from the
first DATA statement in the program (or the first DATA statement in a function or subroutine, if this is where
the RESTORE is executed).
UNREGISTERED
Example: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
end
end
RETURN
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This statement causes program execution to continue at the next statement after a GOSUB command was
issued. RETURN is the last statement in a block of code that is called by the GOSUB command.
See GOSUB
RIGHT$(string, number)
Description:
This function returns a sequence of characters from the right hand side of the string, string variable, or string
expression string using number to determine how many characters to return. If number is 0, then "" (an
empty string) is returned. If number is greater than or equal to the number of characters in string, then string
will itself be returned.
Usage:
Produces:
right handed
And:
Produces:
hello world
Description:
The RMDIR( ) function attempts to remove the directory specified. If the directory removal is successful the
UNREGISTERED
returned valueVERSION
will be 0. If OF CHM TO
the directory PDF was
removal CONVERTER
unsuccessful,By THETA-SOFTWARE
a value indicating a DOS error will be
returned.
Usage:
Description:
This function returns a random number between 0 and 1. The number parameter is usually set to 1, but the
value is unimportant because it is not actually used by the functoin. The function will always return an
arbitrary number between 0 and 1.
Usage:
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command runs external programs. StringExpr1 should represent the full path and filename of a
Windows or DOS executable program, a Just BASIC *.TKN file, or a *.BAT file. This is not a SHELL
command, so you must provide the name of a program or batch file, not a DOS command (like DIR, for
example). Execution of an external program does not cause the calling Just BASIC program to cease
executing.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Here are two examples:
RUN "QBASIC.EXE"
' run Microsoft's QBASIC
Notice in the second example you can include an additional parameter. This is because it runs a Windows
program. Here is a list of the valid parameters we can include when running Windows programs:
HIDE
SHOWNORMAL (this is the default)
SHOWMINIMIZED
SHOWMAXIMIZED
SHOWNOACTIVE
SHOW
MINIMIZE
SHOWMINNOACTIVE
SHOWNA
RESTORE
SCAN
Previous Top Next
Description:
The SCAN statement causes Just BASIC to stop what it is doing for a moment and process Windows
keyboard and mouse messages. This is useful for any kind of routine that needs to run continuously but
which still needs to process button clicks and other actions. In this way, SCAN can be used as an INPUT
statement that doesn't stop and wait.
Example:
nomainwin
WindowWidth = 120
WindowHeight = 95
statictext #clock.time, "xx:xx:xx", 15, 10, 90, 20
button #clock.12hour, "12 Hour", [twelveHour], UL,_
15, 40, 40, 20
button #clock.24hour, "24 Hour", [twentyfourHour], UL,_
60, 40, 40, 20
open "Clock" for window_nf as #clock
print #clock, "trapclose [quit]"
print #clock.time, "!font courier_new 8 15"
print #clock.12hour, "!font ariel 5 11"
print #clock.24hour, "!font ariel 5 11"
goto [twelveHour]
[timeLoop]
goto [timeLoop]
[formatTime]
if twelveHourFormat = 1 then
if hours > 12 then
hours = hours - 12
suffix$ = " PM"
else
if hours = 0 then hours = 12
suffix$ = " AM"
end if
else
suffix$ = ""
end if
formattedTime$ = prefix$+right$("0"+str$(hours), 2)
formattedTime$ = formattedTime$+mid$(time$, 3)+suffix$
UNREGISTERED
returnVERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
twelveHourFormat = 1
UNREGISTERED
time$ VERSION
= "" OF CHM TO PDF CONVERTER By THETA-SOFTWARE
prefix$ = ""
goto [timeLoop]
twelveHourFormat = 0
time$ = ""
prefix$ = " "
goto [timeLoop]
close #clock
end
SEEK
Previous Top Next
Description:
This command seeks to the desired point in the file for reading or writing in a file opened for BINARY
access. SEEK sets the file pointer to the location specified. Data will be read from or written to the file at the
location of the file pointer. See also: LOC( #h )
#handle
This parameter is the handle of a file opened for binary access.
position
This is the new location for the file pointer.
Usage:
Description:
SELECT CASE is a construction for evaluating and acting on sets of conditions. The syntax for Select Case
UNREGISTERED
is: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
SELECT CASE var
CASE x
'basic code
'goes here
UNREGISTERED
CASE y VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
'basic code
'goes here
CASE z
'basic code
'goes here
CASE else
'basic code
'goes here
END SELECT
Details:
SELECT CASE var - defines the beginning of the construct. It is followed by the name variable that will be
evaluated. The variable can be a numeric variable or a string variable, or an expression such as
"a+b".
CASE value - following the SELECT CASE statement, are individual CASE statements, specifying the
conditions to evaluate for the selected variable. Code after the "case" statement is executed if that particular
case evaluates to TRUE. There is no limit to the number of conditions that can be used for evaluation.
CASE ELSE - defines a block of code to be executed if the selected value does not fulfil any other CASE
statements.
Example usage:
num = 3
Strings
SELECT CASE can also evaluate string expressions in a similar way to numeric expressions.
String example:
var$="blue"
Once one of the CASEs has been met, no other case statements are evaluated. In the following example,
since the value meets the condition of the first CASE statement, the second CASE statement isn't
considered, even though the value meets that condition also.
num = 3
3, 5, 10
select case
case (value < 10) or (value > 50 and value < 60)
print "First case"
UNREGISTERED VERSION
case (value OF CHM
> 100) TO PDF
and (value < CONVERTER
200) By THETA-SOFTWARE
print "Second case"
Code:
select case
case day = today
if time < 12 then
do something
else
something else
end if
case month = Jan
do something
case moon = full
something
end select
If the expression "value" is placed after "select case", then none of the CASE statements is met, so CASE
ELSE is triggered, which prints "Not evaluated".
Description:
This function returns the sine of the angle n. The angle n should be expressed in radians.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
for t = 1 to 45
print "The sine of "; t; " is "; sin(t)
next t
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Tip:
There are 2 * pi radians in a full circle of 360 degrees. A formula to convert degrees to radians is: radians =
degrees divided by 57.29577951
Description:
This function will a return a string of n space characters " ", or (ASCII 32). It is useful when producing
formatted output to a file or printer.
Usage:
for x = 1 to 10
print space$(x); "*"
next x
SQR( n )
Previous Top Next
SQR(n)
Description:
This function returns the square root of the number or numeric expressioin n.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Usage:
Description
Statictext lets you place instructions or labels into your windows. This is most often used with a textbox to
describe what to type into it. The text contained in a statictext control is alligned to the left. If the text is too
long to fit the width of the control, it will automatically wrap lines to fit.
#handle
This must be the same as the #handle of the window that contains the statictext control. If #handle.ext is
used, the program can PRINT commands to the statictext control. If the control has no extension, then it
cannot receive commands to change the text label, font or location.
"string"
This is the text displayed on the statictext.
Statictext Commands
Example:
print #handle.ext, "!font times_new_roman 10"
wait
[memberOK]
print #member.name, "!contents? name$"
print #member.address, "!contents? address$"
print #member.city, "!contents? city$"
print #member.state, "!contents? state$"
print #member.zip, "!contents? zip$"
cr$ = chr$(13)
note$ = name$ + cr$ + address$ + cr$ + city$ + cr$ + _
state$ + cr$ + zip$
notice "Member Info" + cr$ + note$
[quit]
close #member
end
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
Stop
Previous Top Next
Description:
STOPMIDI
Description:
UNREGISTERED VERSION
This command OF
stops a MIDI fileCHM
that isTO PDF
being CONVERTER
played By THETA-SOFTWARE
with the PLAYMIDI command. It must be issued before
a new PLAYMIDI command can be issued, and to stop MIDI files from playing when a program ends.
STR$(numericExpression)
Description:
This function returns a string expressing the result of numericExpression.
Usage:
age = 23
age$ = str$(age)
price = 2.99
price$ = str$(price)
totalApples = 37
print "Total number of apples is " + str$(totalApples)
SUB
Previous Top Next
Description:
This statement defines a subroutine. Zero or more parameters may be passed into the subroutine. A
subroutine cannot contain another subroutine definition, nor a function definition.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
The CALL statement is used to access the SUBROUTINE and to pass values into it. The values must be
the same type as the SUB statement defines them to be. So the following example:
Local Variables
The variable names inside a subroutine are scoped locally, meaning that the value of any variable inside a
subroutine is different from the value of a variable of the same name outside the subroutine.
Passing by Reference
Variables passed as arguments into subroutines are passed "by value" which means that a copy of the
variable is passed into the subroutine. The value of the variable is not changed in the main program if it is
changed in the subroutine. A variable may instead by passed "byref" which means that a reference to the
actual variable is passed and a change in the value of this variable in the subroutine affects the value of the
variable in the main program.
Arrays, structs and handles of files, DLLs and windows are global to a Just BASIC program, and visible
inside a subroutine without needing to be passed in.
Special global status is given to certain default variables used for sizing, positioning, and coloring windows
and controls. These include variables WindowWidth, WindowHeight, UpperLeftX, UpperLeftY,
ForegroundColor$, BackgroundColor$, ListboxColor$, TextboxColor$, ComboboxColor$, TexteditorColor$.
The value of these variables, as well as DefaultDir$ and com can be seen and modified in any
subroutine/function.
Branch Labels
Branch labels are locally scoped. Code inside a subroutine cannot see branch labels outside the subroutine,
and code outside a subroutine cannot see branch labels inside any subroutine.
Ending a Subroutine:
The sub definition must end with the expression: end sub
Executing Subroutines
Be sure that a program doesn't accidentally flow into a subroutine. A subroutine should only execute when it
is called by command in the program.
wrong:
for i = 1 to 10
'do some stuff
next i
correct:
for i = 1 to 10
'do some stuff
next i
WAIT
Example:
Usage:
Print TAB(n)
Just BASIC has the ability to use the TAB function for formatting output to the mainwin and to the printer.
"n" is the character location where the next output will be printed. "tab(7)" causes the next output to print
UNREGISTERED VERSION
beginning at column OF CHM
(character) TO"tab(21)"
7, while PDF CONVERTER By THETA-SOFTWARE
causes the next output to print beginning at column 21.
TAB(n) works with both the mainwin PRINT command and with LPRINT.
Description:
This function returns the tangent of the angle n. The angle n should be expressed in radians
Usage:
for t = 1 to 45
print "The tangent of "; t; " is "; tan(t)
next t
Tip:
There are 2 * pi radians in a full circle of 360 degrees. A formula to convert degrees to radians is: radians =
degrees divided by 57.29577951
Description
The textbox command adds a single item, single line text entry control to a window. It is useful for
generating forms and getting small amounts of user input in the form of text.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
#handle.ext
The #handle part must be the same as for the window that contains the textbox control. The ".ext" part must
be unique for the textbox.
Textbox commands:
Example:
print #handle, "!font Times_New_Roman 10";
Sample Program
' sample program
[mainLoop]
wait
[titleGraph]
print #hndl.txt, "!contents?"
input #hndl.txt, graphTitle$
notice "The title for your graph is: "; graphTitle$
close #hndl
end
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
Texteditor
Previous Top Next
Description
Texteditor is a control similar to textbox, but with scroll bars, and with an enhanced command set. The
commands are essentially the same as that of a window of type "text." NOTICE that texteditor commands
start with an exclamation point, because the control will simply display anything printed to it if it doesn't start
with an exclamation point. The texteditor provides a method for the user to create and edit large amounts of
text. The addition of a texteditor control to a window automatically causes the menubar to contain an EDIT
menu. Do not attempt to create an EDIT menu with a MENU command, or it will not function properly.
Right-clicking within a texteditor control pops up an automatic EDIT menu.
#handle.ext
The #handle part must be the same as for the window that contains the texteditor control. The ".ext" part
must be unique for the texteditor.
This works with texteditor controls, but not with textbox controls or text windows.
This causes the edges of the control to maintain their distance from the edges of the overall window. If the
user resizes the window, the texteditor control also resizes.
Example:
print #handle, "!font Times_New_Roman 10";
For information on creating controls with different background colors, see Colors and the Graphical User
Interface .
TIME$( )
Previous Top Next
Description:
This function returns a string representing the current time of the system clock in 24 hour format. This
function replaces the time$ variable used in QBasic. See also DATE$( ) , Date and Time Functions
Usage:
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This commands manages a Windows timer. This is useful for controlling the rate of software execution
(games or animation perhaps), or for creating a program or program feature which activates periodically (a
clock perhaps, or an email client which checks for new messages). The TIMER is deactivated by setting a
time value of 0, and no branch label. There is only one timer. The elapsed time value and/or branch label
to execute can be changed at any time by issuing a new TIMER command. There are 1000 milliseconds in
UNREGISTERED
one second. VERSION OFcauses
A value of 1000 CHM theTOtimer
PDFtoCONVERTER By THETA-SOFTWARE
fire every one second. A value of 500 causes the timer to
fire every half second, and so on.
Usage:
[itHappened]
'deactivate the timer
timer 0
confirm "It happened! Do it again?"; answer
if answer then
'reactivate the timer
timer 3000, [itHappened]
wait
end if
end
Subroutine handler:
sub itHappened
'deactivate the timer
timer 0
confirm "It happened! Do it again?"; answer
if answer then
'reactivate the timer
timer 3000, itHappened
end if
end sub
Be Careful!
If the program attempts to execute more code within a timer routine than can be executed in the timer
interval, the timer ticks build up and the program will keep executing them as quickly as it can. This might
make the program appear to have locked up. To avoid a lock-up, place a SCAN command within the timer
routine, so that the program knows when the user activates other controls, or closes a window.
TRIM$( s$ )
Previous Top Next
TRIM$(stringExpression)
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function removes any spaces from the start and end of the string in stringExpression. This can be
useful for cleaning up data entry among other things.
Usage:
UNREGISTERED VERSION
sentence$ OF CHM "TO PDF CONVERTER By THETA-SOFTWARE
= " Greetings
print len(trim$(sentence$))
Produces: 9
TXCOUNT
Previous Top Next
txcount(#handle)
Description:
This function gets a count of bytes in a serial communications transmit queue.
count = txcount(#com)
UNLOADBMP "name"
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This command removes from Just BASIC the bitmap specified by "name". It also frees the Windows
memory resources associated with that bitmap. This is useful for freeing bitmap resources when many
bitmaps are used in a program. Unload all bitmaps loaded with LOADBMP when a program closes to
insure that system resources are freed. UNLOADBMP should also be used for bitmaps loaded with the
graphics command GETBMP.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
See also: LOADBMP , Graphics Commands
UPPER$( s$ )
Previous Top Next
UPPER$(s$)
Description:
This function returns a copy of the contents of the string, string variable, or string expression s$, but with all
letters converted to uppercase.
Usage:
Produces:
Description:
The special variables UpperLeftX and UpperLeftY specify the distance, in pixels, from the top-left of the
UNREGISTERED
display for theVERSION
next-openedOF CHMFor
window. TOexample,
PDF CONVERTER Bywill
the following code THETA-SOFTWARE
open a graphics window whose
upper left corner is located 50 pixels from the left of the display, and 25 pixels from the top of the display:
UpperLeftX = 50
UpperLeftY = 25
open "test window" for graphics as #testHandle
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
input r$
Description:
The special variables UpperLeftX and UpperLeftY specify the distance, in pixels, from the top-left of the
display for the next-opened window. For example, the following code will open a graphics window whose
upper left corner is located 50 pixels from the left of the display, and 25 pixels from the top of the display:
UpperLeftX = 50
UpperLeftY = 25
open "test window" for graphics as #testHandle
input r$
USING(templateString, numericExpression)
UNREGISTERED
Description: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function formats numericExpression as a string using templateString. The rules for the format are
similar to those in Microsoft BASIC's PRINT USING statement, but since using( ) is a function, it can be
used as part of a larger BASIC expression instead of being useful only for display output directly. The
template string consists of the character "#" to indicate placement for numerals, and a single dot "." to
indicate placement for the decimal point. The template string must be contained within double quotation
UNREGISTERED
marks. If thereVERSION OF CHM
are more digits TOinPDF
contained CONVERTER
a number than allowedBy
for THETA-SOFTWARE
by the template string, the digits will
be truncated to match the template.
template$ = "######.##"
amount$ = using(template$, 1234.56)
Using() may be used in conjunction with 'print'. The following two examples produce the same result:
The using() function for rounds its output like PRINT USING does in other BASICs.
Usage:
VAL(stringExpression)
UNREGISTERED
Description:VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
This function returns a numeric value for stringExpression if stringExpression represents a valid numeric
value or if it begins with a valid numeric value. If not, then zero is returned.
Usage:
UNREGISTERED
print 2VERSION OF CHM TO PDF
* val("3.14") CONVERTER By
Produces: THETA-SOFTWARE
6.28
Version$
Description:
This variable holds the version of Just BASIC, in this case "1.0".
This is useful so that you can take advantage of whatever differences there are between the different
versions of Just BASIC.
Description:
This simple statement causes program execution to stop and wait for user input events. When the user
UNREGISTERED
interacts with VERSION OF CHM
a window or other controlTO PDFbyCONVERTER
owned the program and By THETA-SOFTWARE
generates an event, program execution
resumes at the event handler appropriate for their interaction.
Usage:
[popupMenu]
popupmenu "&Square Spiral", [asSquare], "&Triangular Spiral", [asTriangle]
wait
[asSquare]
print #geo, "cls ; home ; down ; color red"
for x = 1 to 120
print #geo, "go "; x; " ; turn 87"
next x
wait
[asTriangle]
print #geo, "cls ; home ; down ; color blue"
for x = 1 to 120
print #geo, "go "; x; " ; turn 117"
next x
wait
[quit]
close #geo
end
Note: In general, Just BASIC encourages the use of wait rather than input.
WindowHeight
Previous Top Next
Description:
The special variables WindowWidth and WindowHeight specify the width and height of the next window to
be opened. If the program's code does not specify the values for these special variables, their defaults will
be 320 and 360 respectively. After a resize event that is trapped by the resizehandler command, these
variables contain the width and height of the client area of the window. the client area is the workspace of
the window that is contained within the sizing frame, border or titlebar. See resize.bas for an example of this
usage.
Usage:
The following example will open a graphics window 250 pixels wide and 100 pixels high.
WindowWidth = 250
WindowHeight = 100
open "test window" for graphics as #testHandle
input r$
Description:
The special variables WindowWidth and WindowHeight specify the width and height of the next window to
UNREGISTERED
be opened. IfVERSION
the program'sOF CHM
code doesTOnotPDF CONVERTER
specify By THETA-SOFTWARE
the values for these special variables, their defaults will
be 320 and 360 respectively. After a resize event that is trapped by the resizehandler command, these
variables contain the width and height of the client area of the window. the client area is the workspace of
the window that is contained within the sizing frame, border or titlebar. See resize.bas for an example of this
usage.
UNREGISTERED
Usage: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
The following example will open a graphics window 250 pixels wide and 100 pixels high.
WindowWidth = 250
WindowHeight = 100
open "test window" for graphics as #testHandle
input r$
WHILE expression
some code
WEND
Description:
These two statements comprise the start and end of a control loop. Between the WHILE and WEND code is
placed (optionally) that is executed repeatedly while expression evaluates to true. The code between any
WHILE statement and its associated WEND statement will not execute even once if the WHILE expression
initially evaluates to false. Once execution reaches the WEND statement, for as long as the WHILE
expression evaluates to true, then execution will jump back to the WHILE statement. "Expression" can be a
boolean, numeric, or string expression or combination of expressions.
Usage:
Or:
Note: A program SHOULD NOT exit a WHILE...WEND loop using GOTO. It may cause the program to
behave unpredictably. (See EXIT WHILE, below.)
GOSUB, FUNCTION and SUB may be used within a WHILE...WEND loop because they only temporarily
redirect program flow or call on other parts of the program. Program execution resumes within the
WHILE/WEND loop in these instances. Program execution does not return to the WHILE/WEND loop if
GOTO is used within the loop. GOTO should not be used to exit a WHILE/WEND loop. EXIT WHILE will
correctly exit the loop before it would have terminated normally.
The following example is an example of a WHILE...WEND loop exited improperly:
while count < 10
input "Enter a name (or a blank line to quit) ?"; n$
if n$ = "" then [exitLoop]
list$(count) = n$
count = count + 1
wend
[exitLoop]
Description:
This function returns the nth word in the string, string variable or string expression, stringExpression. The
leading and trailing spaces are stripped from stringExpression and then by default it is broken down into
'words' at the remaining spaces inside. If n is less than 1 or greater than the number of words in
stringExpression, then "" is returned. The string delimiter is optional. When it is not used, the space
character is the delimiter.
Usage:
print word$("The quick brown fox jumped over the lazy dog", 5)
Produces:
jumped
And:
Produces:
and
many
miles
to
go
before
I
sleep.
token$ = "*"
parseMe$ = "this,is,,a,test"
idx = 0
while token$<>""
idx = idx + 1
token$ = word$(parseMe$, idx, ",")
if token$ <> "" then print token$
wend
Also, notice the doubled up comma in the test string. This will be returned as a comma. This is useful for
detecting empty delimited fields in a string. Try substituting the following lines:
parseMe$ = "thisarfisarfarfaarftest"
UNREGISTERED
and: VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE