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

74

Part II: Learning Programming with Liberty BASIC

Don’t worry too much about the technical details in using the PRINT and INPUT commands because they represent the old way of getting input and displaying output on-screen. In Windows and other modern operating systems, including the Mac OS, programs offer fancier ways of accepting input and displaying output through the use of a graphical user interface (GUI), often pronounced as goo-ey.

Figure 6-2:

The INPUT command accepts data from a keyboard.

Inputting and Outputting Data:

The Modern Way

Most computers now use a graphical user interface to display data. Because commands such as PRINT and INPUT were geared for ancient computers that few people use any more, most programming languages now include special commands for creating and displaying data by using windows and dialog boxes.

Every programming language provides different types of commands to create and display data in windows, dialog boxes, and menus. The commands in this chapter are unique to Liberty BASIC and probably won’t work in other versions of BASIC.

Getting input

One of the simplest ways to ask for input from the user is to use a special Prompt dialog box. To create a Prompt dialog box, you need to use the

Chapter 6: Handling Input and Output

75

PROMPT command, following it with the text that you want to display (such as asking the user to type a name or number) and a character or word that represents whatever the user types in, as in the following example:

NOMAINWIN

PROMPT “What is the name of your boss?”; name$

The first command (NOMAINWIN) turns off the main window, as described earlier in the chapter. The next command (PROMPT) displays the Prompter dialog box, as shown in Figure 6-3.

Figure 6-3:

The

PROMPT command displays a dialog box so that people can type data into your program.

Displaying output

The simplest way to display output to the user is to use a Notice dialog box. To create a Notice dialog box, you need to use the NOTICE command, following it with any text that you want to display. The following program uses the NOTICE command to display text along with the name that the user types into the Prompt dialog box. In this case, the NOTICE command displays a Notice dialog box, as shown in Figure 6-4.

Figure 6-4:

The

NOTICE command creates a dialog box that displays information to the user.