StPendl
Aug 31, 2010
Table of Contents
Fast FAQ:
by -These issues have been discussed by newcomers to the boards. Have a read
even if you have programming experience,something will be relevant in the near
future and little bells will ring when you feel perplexed.
First some general concepts about Liberty and then a discussion about some of
the more cryptic runtime errors.
Write Run Compile Execute:
Liberty code is drafted in the IDE and stored as a .bas file. When you click onRun or Debug, your code is first compiled, any coding errors cause the compiler
to stop and report. When error free the compiled code goes to runtime and your
instructions are executed and appear on screen in whatever window type you
have specified. So, running a program is a two step process, seamless, but
still two steps. Optionally a .tkn file can be created; it is a precompiled program
that saves a little time when starting up. The .tkn also secures your code from
prying eyes.
Debug:
The compiler will do some of the debugging for you. Once you get to runtime theLadybug icon is your best friend. Go on, click it. Spend as much time with the
debugger as the IDE. Click on the >>> animate icon and watch your program
run line by line. If it gets a runtime error it stops on the offending line and you
can see the content of all your variables at that moment in time.
Window Types:
The first window type you will encounter is Liberty's mainwin. This is the defaultwindow type and is essentially a testing and debugging window. As soon as you
are competent you will be using other window types.
It is great for your first steps into programming and you can write quite complex
programs in this environment, but it has limits. It cannot produce a GUI style
interface. It's styled as a traditional DOS console and cannot produce colored
text. Neither does it support the traditional inkey$() statement, only input$(1).
The essential difference is that program flow stops and waits for input.
You will use the mainwin for development and debugging and a standard
Window for almost everything else. A standard window provides GUI controls
like listboxes, buttons and checkboxes. There are
graphics, text and dialogs. Be aware they exist and take time to choose the
correct window type for the task in hand, but have a good reason to move away
from the standard window type.
Looping Stop Break Kill:
Endless loops are an endearing feature of all programming languages. A simple loop likeWHILE WEND can consume all of the processor cycles that Liberty can get hold of and
if you don't have dual core your PC will freeze as well as the program.
If you are in trouble press
Run, Kill BASIC Programs. Kill program may leave the program in the kill list even though
it’s killed, this is because you opened a window but it did not get closed.
Do put SCAN inside loops. Scan is a very important command that causes Liberty to
check for mouse or keyboard input.
Don't code delay loops like FOR n=1 TO 50000 : NEXT. Liberty operates in a
environment where processing cycles are shared. A delay loop like that hogs the processor.
Use TIMER if you need a pause, or better still WAIT for the next event.
GUI program flow:
Know a bit about BASIC? Cool. To make the transition to GUI you need to have the conceptof "events" firmly in your mind. You set up events, the keyboard might trigger an event, the
mouse might trigger an event, and the timer might trigger an event. A listbox might trigger
an event. Each event has a handler, a code block that will be called when the event fires.
Typically at the end of this code block there will be a WAIT statement. Program execution
sits and waits here till another event fires then it shoots off to action that. You may also use
Subs to handle events.
Events repeat, you need to switch them off if you don't want them to fire again. The timer
statement catches a lot of folks out, switch it off immediately it has fired if you want it to be
a one shot event.
Subs are self contained and don't know much about the outside world. If an event that has a
branch label handler fires while you are in the sub it's going to fail. Switch off events going into
a sub or ensure the event is handled by a sub itself. Best not to mix subs and branching to
labels in GUI code.
Include:
Include is not relevant to Liberty BASIC. For a start the system is complete in itself and needsno libraries attached. There are no restrictions on code size so there is no need to page in and
out segments of code. Code banks are available that let you cut and paste blocks of reusable
code directly to the program. The IDE allows you to jump about the program in a variety of
ways, click the Jump To icon. Liberty also provides direct access to Windows API and third party
dll files.
Typing & Dimming variables:
If you are used to typing variables forget it, this is automated within Liberty. Anything thathas a fractional value beyond the decimal point is stored as a float, anything else is stored
as a long value. Floats are accurate to 16 decimal places and can optionally be viewed in
the debugger (right click).
As in any computer language you have to be aware that comparing two float values is
problematic, they are never really equal. > or < is ok but don't try and see if floatA = floatB.
Use Int() or add epsilon if you must.
Variables initiate automatically with 0 or "" values and in general don't need dimmed though
you can if that’s your habit. Arrays initiate automatically with 10 elements, if you intend to use
more than 10 elements you must dimension the array. Multi
dimmed and should be dimmed at the start of the program. All arrays are global by default
other variables must be specified as global if you wish.
Liberty can hold a whopping 70Mb of variable data at any one time. Beyond that you need
to page data in and out from file.
Graphics:
Liberty has a drawing pen, if you don't have that Down you won't see anygraphics. So set the pen down as the first step in any graphics operation.
Liberty has a Flush command that consolidates recent drawing operations
into a segment. The segment resides in memory and can be redrawn instantly.
You must Flush if you want graphics to stick on screen and not be wiped out
if another window passes over them. Be aware that Flush consumes memory,
use it sparingly and delete any segments you don't need. You can use up your
70Mb of memory in a split second if you misuse the command.
Liberty can scroll, display, scale and print huge graphic resources. But Getbmp
may only capture and save the visible screen as a .bmp.
Printing:
You must Flush if you want to print or scale graphics to the printer. The printerdialog is not able to change from the default printer.
Sorting:
Liberty sorts in Lexographic or Dictionary order. This is different from ASCIIorder which you may be more used to. It is possible to arrange for the sort
to be in ASCII order just be aware of the difference.
Using():
If you use the Using(###.##) statement you will get a % in front of your numberif it is too big to fit in the template.
Liberty Runtime Errors:
Tip, don't cry "bug”, you may feel foolish later :) try reading this and especiallytry running animate in the debugger.
OS Error cannot find file
while building your .exeStart Liberty from the folder you installed it in to begin creating your .exe
Problem Creating File
while building your .exeDon't create your .exe in Liberty's program folder, create it elsewhere.
File System Access Denied
Either the file is already open, perhaps you forgot to close it, or it is in use by anotherprogram or you don't have Windows permission to access it. Network paths need
special handling or mapped to a drive:
Error Opening File
The file is being written to by another program or, you’re on Vista, join the Userclub and get your permissions sorted. You may need to be an Administrator
to gain permission to access the file.
The file is literally invisible
Vista again, get permission.System Primitive Failed
You are out of memory; check what your loops are doing you may be creating avery large number or a very (large) small number.
In addition you may have hit the string length limit, which is about 16,777,216 characters.
Float invalid op
A function failed because of a negative value use abs(n) prior to sqr(n) or log(n)Invalid branch label [xyz]
If it does exist you called it inside a sub that doesn't know where it is, a timer, mouseor keyboard event perhaps. Alternatively you have listed a [label] immediately after
a [label]. Liberty expects code after a [label], don't pen another [label].
Index (nnn) is outside collection bounds
An index is a pointer to a position in an array. Indexes are used in array variables,in record pointers and by the system in bmps. Most often you will have asked for
an array item that does not exist. So check what value is in array(index),
array(index,index) or seek(index).
Argument must be a collection
This is often associated with sending Liberty the wrong set of arguments in acommand string. sending "refresh" to graphicbox for example or using $ values
where numeric values are expected. Animate should stop on the offending line,
double check the help file for the command and examine the values in the variables.
Collection is empty
Liberty expected some arguments but didn't get them, Print "!" to a textbox forexample, Liberty expects arguments after the !command. Animate should stop
on the offending line, double check the help file for the command.
IsEmpty
Liberty found itself without the information it needed. This is most often program flow.Search for missing ends, end sub, end if, next. Practice indenting your code so that
code blocks are easily visible. Make sure code does not run through to code blocks
you didn't expect it to reach. Ensure Waits are placed where required.
Other reasons for this error are missing arguments or missing data, file access denial
or Liberty finding Null info where it expected something.
This is sometimes the hardest to debug because program flow errors turn up anywhere
but where the error was made. Use animate but don't assume the line shown is the cause.
Find the error.log and see what fragments of code are mentioned in it.
Start manual debugging, use step through a line at a time and make sure you are going
where you expected. Code in notices or use the run to break option in the debugger.
Hey debugging is part of the fun.
Up to date on info on everything that is discussed above is available in more detail within
the Forums. Use the search features, remember to set the period to >7 days and the
items to >10. Do not underestimate the power of the Help File, browse again and again.
Protection violation
If using API functions, you may have passed a numerical argument by value instead of by reference.You need to use a struct to allow the API function to fill the argument with a value.
It might as well be possible, that you did not use the correct data type, so make sure to check the C definition of the API function.