Well Come to Professional Programmers

Learning Goal

Learning is a process to acquire, enhance, or make changes in one's knowledge. Learning Module presents essential and masks non-essential pieces of knowledge. It is self paced and presents required links to important examples and related terminologies essentially required for examination centric study. The module is focused on examination system in vogue in Pakistan and helps student acquire maximum marks in limited time of study.

Sunday, April 25, 2010

Getting Started with GW-BASIC



Chapter 2
Getting Started with GW-BASIC



This chapter describes how to load GW-BASIC into your system. It also explains the two different types of operation modes, line formats, and the various elements of GW-BASIC.



2.1 Loading GW-BASIC


To use the GW-BASIC language, you must load it into the memory of your computer from your working copy of the MS-DOS diskette. Use the following procedure:



  1. Turn on your computer.

  2. Insert your working copy of the MS-DOS diskette into Drive A of your computer, and press RETURN.

  3. Type the following command after the A> prompt, and press RETURN:


    gwbasic




Once you enter GW-BASIC, the GW-BASIC prompt, Ok, will replace the MS-DOS prompt, A>.


On the screen, the line XXXXX Bytes Free indicates how many bytes are available for use in memory while using GW-BASIC.


The function key (F1–F10) assignments appear on the bottom line of the screen. These function keys can be used to eliminate key strokes and save you time. Chapter 4, "The GW-BASIC Screen Editor," contains detailed information on function keys.



2.2 Modes of Operation


Once GW-BASIC is initialized (loaded), it displays the Ok prompt. Ok means GW-BASIC is at command level; that is, it is ready to accept commands. At this point, GW-BASIC may be used in either of two modes: direct mode or indirect mode.



2.2.1 Direct Mode


In the direct mode, GW-BASIC statements and commands are executed as they are entered. Results of arithmetic and logical operations can be displayed immediately and/or stored for later use, but the instructions themselves are lost after execution. This mode is useful for debugging and for using GW-BASIC as a calculator for quick computations that do not require a complete program.



2.2.2 Indirect Mode


The indirect mode is used to enter programs. Program lines are always preceded by line numbers, and are stored in memory. The program stored in memory is executed by entering the RUN command.



2.3 The GW-BASIC Command Line Format


The GW-BASIC command line lets you change the environment or the conditions that apply while using GW-BASIC.



2.4 GW-BASIC Statements, Functions, Commands, and Variables


A GW-BASIC program is made up of several elements: keywords, commands, statements, functions, and variables.



2.4.1 Keywords


GW-BASIC keywords, such as PRINT, GOTO, and RETURN have special significance for the GW-BASIC Interpreter. GW-BASIC interprets keywords as part of statements or commands.


Keywords are also called reserved words. They cannot be used as variable names, or the system will interpret them as commands. However, keywords may be embedded within variable names.


Keywords are stored in the system as tokens (1- or 2-byte characters) for the most efficient use of memory space.



2.4.2 Commands


Commands and statements are both executable instructions. The difference between commands and statements is that commands are generally executed in the direct mode, or command level of the interpreter. They usually perform some type of program maintenance such as editing, loading, or saving programs. When GW-BASIC is invoked and the GW-BASIC prompt, Ok, appears, the system assumes command level.



2.4.3 Statements


A statement, such as ON ERROR...GOTO, is a group of GW-BASIC keywords generally used in GW-BASIC program lines as part of a program. When the program is run, statements are executed when, and as, they appear.



2.4.4 Functions


The GW-BASIC Interpreter performs both numeric and string functions.



2.4.4.1 Numeric Functions


The GW-BASIC Interpreter can perform certain mathematical (arithmetical or algebraic) calculations. For example, it calculates the sine (SIN), cosine (COS), or tangent (TAN) of angle x.


Unless otherwise indicated, only integer and single-precision results are returned by numeric functions.



2.4.4.2 String Functions


String functions operate on strings. For example, TIME$ and DATE$ return the time and date known by the system. If the current time and date are entered during system start up, the correct time and date are given (the internal clock in the computer keeps track).



2.4.4.3 User-Defined Functions


Functions can be user-defined by means of the DEF FN statement. These functions can be either string or numeric.



2.4.5 Variables


Certain groups of alphanumeric characters are assigned values and are called variables. When variables are built into the GW-BASIC program they provide information as they are executed.


For example, ERR defines the latest error which occurred in the program; ERL gives the location of that error. Variables can also be defined and/or redefined by the user or by program content.


All GW-BASIC commands, statements, functions, and variables are individually described in the GW-BASIC User's Reference.



2.5 Line Format


Each of the elements of GW-BASIC can make up sections of a program that are called statements. These statements are very similar to sentences in English. Statements are then put together in a logical manner to create programs. The GW-BASIC User's Reference describes all of the statements available for use in GW-BASIC.


In a GW-BASIC program, lines have the following format:


nnnnn statement[statements]

nnnnn is a line number


statement is a GW-BASIC statement.


A GW-BASIC program line always begins with a line number and must contain at least one character, but no more than 255 characters. Line numbers indicate the order in which the program lines are stored in memory, and are also used as references when branching and editing. The program line ends when you press the RETURN key.


Depending on the logic of your program, there may be more than one statement on a line. If so, each must be separated by a colon (:). Each of the lines in a program should be preceded by a line number. This number may be any whole integer from 0 to 65529. It is customary to use line numbers such as 10, 20, 30, and 40, in order to leave room for any additional lines that you may wish to include later. Since the computer will run the statements in numerical order, additional lines needn't appear in consecutive order on the screen: for example, if you entered line 35 after line 60, the computer would still run line 35 after line 30 and before line 40. This technique may save your reentering an entire program in order to include one line that you have forgotten.


The width of your screen is 80 characters. If your statement exceeds this width, the cursor will wrap to the next screen line automatically. Only when you press the RETURN key will the computer acknowledge the end of the line. Resist the temptation to press RETURN as you approach the edge of the screen (or beyond). The computer will automatically wrap the line for you. You can also press CTRL-RETURN, which causes the cursor to move to the beginning of the next screen line without actually entering the line. When you press RETURN, the entire logical line is passed to GW-BASIC for storage in the program.


In GW-BASIC, any line of text that begins with a numeric character is considered a program line and is processed in one of three ways after the RETURN key is pressed:



  • A new line is added to the program. This occurs if the line number is legal (within the range of 0 through 65529), and if at least one alpha or special character follows the line number in the line.

  • An existing line is modified. This occurs if the line number matches the line number of an existing line in the program. The existing line is replaced with the text of the newly-entered line. This process is called editing.



2.6 Returning to MS-DOS


Before you return to MS-DOS, you must save the work you have entered under GW-BASIC, or the work will be lost.


To return to MS-DOS, type the following after the Ok prompt, and press RETURN:


system

The system returns to MS-DOS, and the A> prompt appears on your screen.



No comments:

Post a Comment