Liberty Basic, A natural Choice for a G Code Foundation
This is a great language to learn the basics of programming, sticking to the foundation, rather then going
into complicated higher level subjects too soon such as object oriented or memory allocation. Because G
code is very similar to BASIC, and does not require to much higher level newer progrmaming techniques,
learning Liberty is a great way to get some inexpensive at home expierience.
The best way to learn anything is to start practicing it. If you want to
learn computer programming, you should start writing programs on your computer
as soon as possible.
You can learn to program by starting out with one of hundreds of programming
languages designed for novices, such as Pascal, LOGO, and SmallTalk.
But the most popular beginner’s programming language is still BASIC. BASIC
is simple enough to help you understand the concepts behind programming
yet powerful enough to enable you to create commercial-quality programs.
To help you in your quest to learn programming, this book comes with a
shareware copy of Liberty BASIC. As long as you’re running Windows 95/98/
Me/NT/2000/XP, you can run and use Liberty BASIC on your computer. Most
of this book provides examples in Liberty BASIC that you can type yourself.
If you have a Macintosh, you can’t run Liberty BASIC unless you buy a
special Windows emulation program such as VirtualPC from Microsoft
(at www.microsoft.com). As an alternative, you can use either True Basic
(www.truebasic.com) or Future Basic (www.stazsoftware.com). True
Basic, Future Basic, and Liberty BASIC all use BASIC language, so the sample
programs in this book designed for Liberty BASIC should run under both
True Basic and Future Basic with only minor modifications.
If for some odd reason you’re both technically knowledgeable enough to use
Linux, yet still want to learn how to program, you can download a free BASIC
interpreter, YABASIC (which stands for Yet Another BASIC), by visiting www.
yabasic.de.
Why Learn Liberty BASIC?
If you’re interested in learning to program, you may wonder, “Why not jump
right in and start learning C++ or Java?” (Then again, if you want to learn how
to swim, why not jump right into the ocean and start swimming with the
sharks?) Although you can start learning to program by using any language,
Liberty BASIC offers several advantages that you won’t find in other language
compilers.
Liberty BASIC is (almost) free
Liberty BASIC is a shareware program that you can evaluate for free until you
decide whether it’s worth paying for. That way, you can experiment with computer
programming without spending any money buying programs, such as
Visual C++ or JBuilder only to realize they may be too complicated and confusing
for you.
Liberty BASIC is easy
Liberty BASIC can teach you the fundamentals of programming so that you
can get real-life experience programming your own computer. Other programming
languages, such as C++ or Java, can force you to master needlessly complicated
topics, such as pointers, object-orientation, and memory allocation.
Rather than let these other programming languages bury you under an additional
layer of complexity that only gets in your way, learn Liberty BASIC.
Best of all, the BASIC programming language was specially designed to teach
novices how to program, so learning BASIC can teach you how programming
works. Once you learn the fundamentals of programming with Liberty BASIC,
you can apply your programming knowledge to help you better learn another
programming language, such as C++ or Java.
Liberty BASIC runs on Windows
When computers used to run the ancient operating system of MS-DOS,
Microsoft tossed in a free BASIC interpreter called QBASIC. Although you can
62 Part II: Learning Programming with Liberty BASIC
still run QBASIC in most versions of Windows (such as Windows 98 but not
Windows 2000), people have been screaming for a Windows-based version of
BASIC that they can use to teach themselves programming.
Because Microsoft has no intention of creating a Windows-based version
of QBASIC, the next alternative is to use Liberty BASIC. You can not only
write BASIC programs in Liberty BASIC on any computer that runs Microsoft
Windows, but you can also create real, honest-to-goodness Windows applications
using Liberty BASIC that you can sell or give away as well.
If you pay for the full version of Liberty BASIC, you can create real Windows
programs that you can sell to others. The shareware version of Liberty BASIC
(which comes with this book) allows you to write programs, but won’t allow
you to compile and distribute them to others.
You can start using Liberty BASIC today
Liberty BASIC comes with this book, so everyone reading this book can start
using it right away (unless, of course, you’re not using Windows). That makes
Liberty BASIC a natural learning tool to complement this book.
If trying to understand certain programming concepts confuses you, you can
quickly type a sample Liberty BASIC program and see for yourself exactly
how certain programming features work. By combining theory with hands-on
experience, this book and Liberty BASIC can help you pick up computer programming
in no time.
Installing Liberty BASIC
To install Liberty BASIC by using the CD that comes with this book, refer to
the installation instructions in the Appendix.
Because software changes so rapidly, a newer version of Liberty BASIC may
be available by the time you read this book. If you download a newer version
from the Liberty BASIC Web site (at www.libertybasic.com), you may need
to go through some extra steps to install Liberty BASIC on your computer.
If you download Liberty BASIC from the Liberty BASIC Web site, the file is
compressed in a self-extracting EXE file. To decompress this file, you need to
download and save this file somewhere on your hard disk, and then doubleclick
on the Liberty Basic EXE file (which has a cryptic name such as lb400win.
exe). When you double-click on the Liberty Basic EXE file, the Liberty Basic
installation program guides you, step-by-step, into installing Liberty Basic on
your computer.
Chapter 5: Getting Your Hands on a Real Language: Liberty BASIC 63
Loading Liberty BASIC
As you install Liberty BASIC, the program creates its own directory and adds
Liberty BASIC to your Program menu. To load Liberty BASIC, follow these
steps:
1. Click the Start button on the Windows taskbar.
The Start menu opens.
2. Choose Programs➪Liberty BASIC➪Liberty BASIC.
The Liberty BASIC program appears.
To make loading Liberty BASIC easier and faster, you can place a Liberty
BASIC icon on the Windows desktop.
To place a Liberty BASIC icon on your Windows desktop, follow these steps:
1. Right-click the Windows desktop.
A pop-up menu appears.
2. Choose New➪Shortcut.
A Create Shortcut dialog box appears.
3. Click Browse.
A Browse dialog box appears.
4. Find and click the Liberty BASIC program and then click Open.
You may need to change directories or drives to find the Liberty BASIC
program if it isn’t stored in the C:\Program Files\Liberty Basic directory.
After you click Open, the Create Shortcut dialog box appears again.
5. Click Next.
The Select a Title for the Program dialog box appears.
6. Type a name, such as Liberty BASIC, in the Select a Name for the
Shortcut text box and click Finish.
The Liberty BASIC icon appears on your desktop. The next time that you
want to load Liberty BASIC, just double-click this icon.
Your First Liberty BASIC Program
The Liberty BASIC editor is where you write, edit, and run your BASIC program.
To see the power of Liberty BASIC, type the following into the Liberty
BASIC editor:
64 Part II: Learning Programming with Liberty BASIC
PRINT “This BASIC program mimics a really bad boss.”
PRINT “What is your name?”
INPUT Name$
PRINT “Hello “ + Name$ + “. You’re fired! Have a nice day.”
END
Liberty BASIC, like most versions of BASIC, doesn’t care whether you type
commands in uppercase, lowercase, or a mixture of both. Most programmers,
however, like to use all uppercase to identify all the BASIC commands that
they use in a program.
Unlike a word processor, the Liberty BASIC editor doesn’t wrap words from
one line to the other, which means that you can keep typing all the way to the
far right until your text scrolls out of view.
This program tells the computer to perform the following tasks:
1. The first line prints the message This BASIC program mimics a
really bad boss. on-screen.
2. The second line prints (adds) a blank line directly underneath the
message.
3. The third line prints What is your name? on-screen.
4. The fourth line displays a question mark (?) as a prompt and waits for
the user to type a name. As soon as the user presses the Enter key, the
BASIC program stores whatever the user types into a temporary
memory location that it identifies as Name$.
5. The fifth line prints the message “Hello (following it by the name that
the user types in the fourth line). You’re fired! Have a nice
day.” The plus sign (+) tells Liberty BASIC to add the word “Hello”
with the words that it stores in Name$.
6. The sixth line tells the computer that this is the end of the program.
Running a Liberty BASIC program
After you finish typing a BASIC program, press Shift+F5 or choose Run➪Run
from the Liberty BASIC menu bar to run the program. Figure 5-1 shows what
the BASIC program from the preceding section looks like when run on Liberty
BASIC.
As you run this program, Liberty BASIC displays the text in a window that it
calls the main window. You can use the menu bar in the main window to print
or save any text that appears in the main window.
Chapter 5: Getting Your Hands on a Real Language: Liberty BASIC 65
Saving a Liberty BASIC program
Although you can type your Liberty BASIC programs over and over whenever
you want to run them, saving your program to a hard drive or floppy disk is
much easier. Then you can load and edit the program later.
To save a program, follow these steps:
1. Choose File➪Save from the Liberty BASIC menu bar, or click the Save
File icon on the Liberty Basic toolbar as shown in Figure 5-2.
The Save As dialog box appears.
2. Type a name for your file in the Filename text box.
You may want to change folders or drives to store your Liberty BASIC file.
3. Click OK.
Liberty BASIC automatically adds a BAS file extension to Liberty BASIC programs
that you save. Unless you have a good reason to change this file extension,
use the BAS extension to help you identify your Liberty BASIC programs
from any other files stored on your computer.
Main window
Figure 5-1:
Running
your first
Liberty
BASIC
program.