StPendl
Sep 1, 2010
[[toc]] =Fast FAQ:= by [[user:RodBird]] These issues have been discussed by newcomers to the boards. Have a readeveneven if you have programming experience,something will be relevant in the nearfuturefuture and little bells will ring when you feel perplexed. First some general concepts about Liberty and then a discussion about some ofthethe more cryptic runtime errors. ==Write Run Compile Execute:== Liberty code is drafted in the IDE and stored as a .bas file. When you click onRunRun or Debug, your code is first compiled, any coding errors cause the compilertoto stop and report. When error free the compiled code goes to runtime and yourinstructionsinstructions are executed and appear on screen in whatever window type youhavehave specified. So, running a program is a two step process, seamless, butstillstill two steps. Optionally a .tkn file can be created; it is a precompiled programthatthat saves a little time when starting up. The .tkn also secures your code frompryingprying eyes. ==Debug:== The compiler will do some of the debugging for you. Once you get to runtime theLadybugLadybug icon is your best friend. Go on, click it. Spend as much time with thedebuggerdebugger as the IDE. Click on the >>> animate icon and watch your programrunrun line by line. If it gets a runtime error it stops on the offending line and youcancan 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 defaultwindowwindow type and is essentially a testing and debugging window. As soon as youareare competent you will be using other window types. It is great for your first steps into programming and you can write quite complexprogramsprograms in this environment, but it has limits. It cannot produce a GUI styleinterface.interface. It's styled as a traditional DOS console and cannot produce coloredtext.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 standardWindowWindow for almost everything else. A standard window provides GUI controlslikelike listboxes, buttons and checkboxes. There are specialized windows forgraphics,graphics, text and dialogs. Be aware they exist and take time to choose thecorrectcorrect window type for the task in hand, but have a good reason to move awayfromfrom the standard window type. ==Looping Stop Break Kill:== Endless loops are an endearing feature of all programming languages. A simple loop likeWHILEWHILE WEND can consume all of the processor cycles that Liberty can get hold of andifif you don't have dual core your PC will freeze as well as the program. If you are in trouble press Ctrl+Break Then navigate to the IDE and from the Menu selectRun,Run, Kill BASIC Programs. Kill program may leave the program in the kill list even thoughit’sit’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 tocheckcheck for mouse or keyboard input. Don't code delay loops like FOR n=1 TO 50000 : NEXT. Liberty operates in a multi-threadedenvironmentenvironment 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.[[toc]]==GUI program flow:== Know a bit about BASIC? Cool. To make the transition to GUI you need to have the conceptofof "events" firmly in your mind. You set up events, the keyboard might trigger an event, themousemouse might trigger an event, and the timer might trigger an event. A listbox might triggeranan 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 executionsitssits and waits here till another event fires then it shoots off to action that. You may also useSubsSubs to handle events. Events repeat, you need to switch them off if you don't want them to fire again. The timerstatementstatement catches a lot of folks out, switch it off immediately it has fired if you want it to beaa one shot event. Subs are self contained and don't know much about the outside world. If an event that has abranchbranch label handler fires while you are in the sub it's going to fail. Switch off events going intoaa sub or ensure the event is handled by a sub itself. Best not to mix subs and branching tolabelslabels in GUI code. [[toc]] ==Include:== Include is not relevant to Liberty BASIC. For a start the system is complete in itself and needsnono libraries attached. There are no restrictions on code size so there is no need to page in andoutout segments of code. Code banks are available that let you cut and paste blocks of reusablecodecode directly to the program. The IDE allows you to jump about the program in a variety ofways,ways, click the Jump To icon. Liberty also provides direct access to Windows API and third partydlldll files. ==Typing & Dimming variables:== If you are used to typing variables forget it, this is automated within Liberty. Anything thathashas a fractional value beyond the decimal point is stored as a float, anything else is storedasas a long value. Floats are accurate to 16 decimal places and can optionally be viewed inthethe debugger (right click). As in any computer language you have to be aware that comparing two float values isproblematic,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 thoughyouyou can if that’s your habit. Arrays initiate automatically with 10 elements, if you intend to usemoremore than 10 elements you must dimension the array. Multi dimension arrays must bedimmeddimmed and should be dimmed at the start of the program. All arrays are global by defaultotherother 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 needtoto 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.graphics. So set the pen down as the first step in any graphics operation. Liberty has a Flush command that consolidates recent drawing operationsintointo 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 outifif another window passes over them. Be aware that Flush consumes memory,useuse it sparingly and delete any segments you don't need. You can use up your70Mb70Mb of memory in a split second if you misuse the command. Liberty can scroll, display, scale and print huge graphic resources. But Getbmpmaymay 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 printerdialogdialog is not able to change from the default printer.[[toc]]==Sorting:== Liberty sorts in Lexographic or Dictionary order. This is different from ASCIIorderorder which you may be more used to. It is possible to arrange for the sorttoto 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 numberifif 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 especiallytrytry running animate in the debugger. ===OS Error cannot find file=== while building your .exe Start Liberty from the folder you installed it in 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 anotherprogramprogram or you don't have Windows permission to access it. Network paths needspecialspecial handling or mapped to adrive:drive. [[toc]] ===Error Opening File=== The file is being written to by another program or, you’re on Vista, join the Userclubclub and get your permissions sorted. You may need to be an Administratortoto 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 averyvery 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, mouseoror keyboard event perhaps. Alternatively you have listed a [label] immediately afteraa [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,inin record pointers and by the system in bmps. Most often you will have asked foranan array item that does not exist. So check what value is in array(index),array(index,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 acommandcommand string. sending "refresh" to graphicbox for example or using $ valueswherewhere numeric values are expected. Animate should stop on the offending line,doubledouble check the help file for the command and examine the values in the variables.[[toc]]===Collection is empty=== Liberty expected some arguments but didn't get them, Print "!" to a textbox forexample,example, Liberty expects arguments after the !command. Animate should stoponon 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 thatcodecode blocks are easily visible. Make sure code does not run through to code blocksyouyou 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 denialoror Liberty finding Null info where it expected something. This is sometimes the hardest to debug because program flow errors turn up anywherebutbut 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 goingwherewhere 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 withinthethe Forums. Use the search features, remember to set the period to >7 days and theitemsitems 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. ===String can't hold string=== You are using an UNC path (\\Server\Share) to access your program. To make things work you must map the shared drive to a drive letter. LB does not support UNC paths for the executables.