Liberty BASIC Default Variables
Internet - Downloading a File to Disk
API Corner - Easy Font Manipulations
Mapping Real World Coordinates
A few variables are made automatically as you load any program in Liberty BASIC. This article will describe the various definitions and helpful applications of them.
Firstly, here is a list of them:
BackgroundColor$ ComboboxColor$ CommandLine$ DefaultDir$ DisplayHeight DisplayWidth Drives$ ForegroundColor$ ListboxColor$ Platform$ PrintCollate PrintCopies PrinterName$ TextboxColor$ TexteditorColor$ Version$ WindowHeight WindowWidth UpperLeftX UpperLeftY
You probably recognise some of them (if not most of them) and have already used them in your programs. For example, you may have used WindowHeight and WindowWidth whilst making windows in LB, FreeForm or LB Workshop. Hopefully you will be able to make full screen windows with a yellow background and pink textboxes by the end of this article!
These variables control the different colours for the controls in a window (for example, ComboboxColor$ changes the colour of comboboxes). The two variables BackgroundColor$ and ForegroundColor$ control the background and foreground colours of the window (not including the controls). When you define the variables' values, you must only fill them with these colour names: black, blue, brown, buttonface, cyan, darkblue, darkcyan, darkgray, darkgreen, darkpink, darkred, green, lightgray, palegray, pink, red, white and yellow.
Here is an example of all of these colour controls in a window!
ForegroundColor$ = "Brown" BackgroundColor$ = "Yellow" TexteditorColor$ = "Blue" TextboxColor$ = "Pink" ComboboxColor$ = "Green" ListboxColor$ = "Red" textbox #main.textbox1, 15, 15, 137, 24 texteditor #main.texteditor1, 15, 55, 135, 115 listbox #main.list1, nothing$(), [nowhere], 165, 15, 105, 120 combobox #main.combo1, nothing$(), [nowhere], 165, 150, 105, 300 open "Colours Galore!" for window as #main print #main, "trapclose [quit]" wait [quit] close #main end
The four variables above are very useful. Below are their definitions:
So, for example, if I wanted to have a 200 x 100 pixel window, I would type into LB:
WindowWidth = 200 WindowHeight = 100 Open "My Program" for window as #program Wait
This would open a 200 x 100 pixel window.
If you need a full screen game, you would need the window being used to be the same size as your screen. A lot of people have their screen resolution as 800 x 600, so to make a full screen window on that computer you would write:
WindowWidth = 800 WindowHeight = 600 Open "My Program" for window as #program Wait
The problem comes when your screen resolution is 1024 x 768! To fix this, the variables DisplayWidth and DisplayHeight can be used. On a 800 x 600 computer, DisplayWidth = 800 and DisplayHeight = 600 and on a 1024 x 768 computer, DisplayWidth = 1024 and DisplayHeight = 768. Try this program - it should be full screen!
WindowWidth = DisplayWidth WindowHeight = DisplayHeight Open "My Program" for window as #program Wait
After "printerdialog" has been used, the three global printer variables are set.
PrinterName$ contains the name of the selected printer e.g. "EPSON Stylus C40 Series" and PrintCollate refers to your options set in printerdialog.
If your printer driver is new enough to handle multiple copies, PrintCopies will be "1" and your program can just print once (lprint). On the other hand, if the printer driver cannot do that, PrintCopies is the number of copies chosen in printerdialog. You need to make a loop to print you text if this is the case.
For i = 1 to PrintCopies Lprint "Hello" Next i
N.B. In LB2, this works differently. See the helpfile for more details.
CommandLine$ contains any parameters passed into LB or run.exe. For example, if you went to Start -> Run and typed "run.exe hello", the program...
print CommandLine$ wait
DefaultDir$ is a variable that tells you the directory that the program is running from. For example, if you saved a program to c:\myfiles\lb progs\calc.bas then when it was run, DefaultDir$ would equal c:\myfiles\lb progs.
Drives$ contains information about the names of all your drives (e.g. floppy drive, hard disk(s), CD-ROMs, DVDs). On most PCs it would contain "a: c: d:" referring to a floppy drive, a hard drive and a CD drive. If a CD-RW (t:\) and a DVD drive (z:\) were added, Drives$ would be "a: c: d: t: z:". This is helpful for making file utilities as you know what drives you can search.
Platform$ is "Windows" if you are using Windows (any version) or "OS/2" if you are using LB for OS/2.
Version$ simply contains the version of LB being used to run the program. If you were using LB v1.42 then Version$ would be "1.42" and if you were using LB v4.0 pre alpha 1 then Version$ would be "4.0 pre alpha 1".
The good thing about all of these global variables is that you don't need to call APIs to access the information that you want although you could do. There are some things however that require APIs and some are harder than others to call. It therefore is a good idea to use the global variables in LB and then add APIs on top for the more complicated things.
Can you make a full screen window with a brown background and a yellow listbox which displays information about your drives?