Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Programming for Dummies 2004.pdf
Скачиваний:
109
Добавлен:
17.08.2013
Размер:
8.05 Mб
Скачать

64

Part II: Learning Programming with Liberty BASIC

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:

Chapter 5: Getting Your Hands on a Real Language: Liberty BASIC

65

PRINT “This BASIC program mimics a really bad boss.”

PRINT

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.

66

Part II: Learning Programming with Liberty BASIC

Main window

Figure 5-1:

Running your first Liberty BASIC program.

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.

Chapter 5: Getting Your Hands on a Real Language: Liberty BASIC

67

New file

Open file

Save file

Figure 5-2:

The Liberty BASIC toolbar provides shortcuts for accessing the most common Liberty Basic commands.

Loading or starting a Liberty

BASIC program

Liberty BASIC can display only one BASIC program on-screen at a time. Any time that you want to view another BASIC program, you must get rid of the BASIC program that you currently have on-screen.

To create a brand new program, follow these steps:

1.Choose File New File from the Liberty BASIC menu bar, or click the

New File icon on the Liberty BASIC toolbar.

If you haven’t saved the BASIC program you’re currently displaying, a Please Confirm dialog box appears.

68

Part II: Learning Programming with Liberty BASIC

2.Click Yes to save the current file or click No if you don’t want to save your changes.

Liberty BASIC displays a blank screen, ready for you to type a new BASIC program.

To load a previously saved program, follow these steps:

1.Choose File Open from the Liberty BASIC menu bar, or click the

Open File icon on the Liberty BASIC toolbar.

If you haven’t saved the BASIC program you’re currently displaying, a

Please Confirm dialog box appears.

Liberty BASIC automatically remembers the last seven files you opened, so for a quick way to load a recently opened file, just click the File menu followed by the name of the file you want to open, which appears at the bottom of the File menu.

2.Click Yes to save the current file or click No if you don’t want to save your changes.

The Open a BAS File dialog box appears. You may need to change directories or drives to find where you saved the file.

3.Click the file that you want to open and then click OK.

Your chosen program appears.

Using Keystroke Commands

in Liberty BASIC

The Liberty BASIC editor works like a simple word processor. You can use the mouse or the keyboard to navigate a BASIC program. Table 5-1 shows the different keys that you can press and what they do.

Table 5-1

Commands for the Liberty BASIC Editor

Keystroke Command

What It Does

Home

Moves the cursor to the front of the line

 

 

End

Moves the cursor to the end of the line

 

 

Shift+Arrow key

Highlights text in the direction of the arrow

 

 

Delete

Deletes the character directly above the cursor or

 

deletes an entire highlighted block of text