Older Version Newer Version

RodBird RodBird Oct 28, 2008

Fast FAQ:
These issues were discussed by newcomers on the boards. Have a quick scan even if you have programming
experience. Something will be relevant now or in the near future. Hopefully little bells will ring when you are feeling
perplexed.
I'm going to split this into two parts. Firstly some general concepts about Liberty and the environment it creates
and then error handling. The section on error handling tackles those that slip past Liberty's compile time check.
Liberty's programming environment:
Write Run Compile Execute:
Liberty code is drafted in the IDE and stored as a .bas file. When you click on Run 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 the Ladybug 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 default window 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 specialised windows for 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 like WHILE 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 CtrlBreak Then navigate to the IDE and from the Menu select Run, Kill BASIC Programs.
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 multithreaded 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 concept of "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 needs no 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.
Liberty 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 that has a fractional value beyond the
decimal point is stored as a float, anything else is stored as a long (4Byte) value. 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 one float = another float. 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.
Arrays are global by default others must be specified as global.
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 any graphics. 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. You must Flush if you want to print or scale graphics to the printer. 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.
Sorting:
Liberty sorts in Lexographic or Dictionary order. This is different from ASCII order 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.
Trivia:
If you use the Using(###.##) statement you will get a % in front of your number if it is too big to fit in the template. The
printer dialog is not able to change from the default printer. Goto [label] needs a command after the label not another [label].
Kill program may leave the program in the kill list even though it’s killed.
Liberty Runtime Errors:
A tip, don't cry "bug”, you may feel foolish later :) try reading this and especially try running animate in the debugger.
OS Error cannot find file......... while building your .exe
Start Liberty from the folder you installed it from to begin creating your .exe
Problem Creating File.............. while building your .exe
Don'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 another program 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 User club and get your permissions sorted out.
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 a very large number or a very (large) small
number.
Invalid branch label [xyz].........
If it does exist you called it inside a sub that doesn't know where it is, an event perhaps.
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 a command string. sending "refresh" to
graphicbox for example or using $ values where numeric values are expected. Animate should stop on the offending l
ine, 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 for example, 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.
Hey debugging is part of the fun.