Classic Computer Magazine Archive START VOL. 3 NO. 7 / FEBRUARY 1989

Programming In BASIC

Using True BASIC: An Overview

by Delmar Searls


Editor's Note: This issue, well turn away from GFA BASIC to look at True BASIC, written by the fathers of all BASICs. Over the next few issues, we'll continue to examine True BASIC, but never fear, we won't forget GFA BASIC!

In 1964, Dr. John Kemeny and Dr. Thomas Kurtz of Dartmouth College developed BASIC (Beginner's All-Purpose Symbolic Instruction Code) in an attempt to create a computer language that was easy to learn and easy to use Today, it's the most widely used computer language.

Since 1964, BASIC has undergone a great many changes. Because it has been implemented on so many different computers, its characteristics vary from machine to machine and from interpreter to interpreter. BASIC has also been influenced by the growing emphasis in computer science on well-structured programming. As a result, many implementations, such as GFA BASIC 3.0, bear only a passing resemblance to BASIC as it was originally conceived. In order to bring their original BASIC up to date, Kemeny and Kurtz developed True BASIC.


Features of True BASIC

True BASIC is available for the Atari ST, Amiga, Macintosh and IBM PC. Though to a great extent programs written on one machine will run on any of the others, each version of True BASIC includes certain features designed to take advantage of the specific hardware and operating system design of that computer. Programs using these special features must be modified before they will run on a different machine.

There are three main ways in which True BASIC differs from "standard" BASIC (as we'll refer to it here): True BASIC includes new control structures, new statements and a new programming environment.

Do While Condition 
      Body of Loop 
  Loop

Figure 1. In a Do-While loop a condition is tested before the body of the loop is executed. While the condition remains true, the progrom will stoy in the loop. When the condition becomes false, the progrom will exit the loop.


Do 
    Body of Loop 
  Loop Until Conditlon

Figure 2. In a Do-Until loop a condition is tested following the execution of the body of the loop. If the condition is false, the loop is repeated. The program stays in the loop until the condition becomes true.


Control Structures

In any programming language, the control structures determine the order in which statements are executed. In standard BASIC the control structures are the For-Next loop, the If-Then-Else statement, the Gosub-Return subroutine call and the Goto statement. (Some newer versions of BASIC provide the While-Wend or Repeat-Until loop.) In addition to For-Next, True BASIC includes a versatile Do-Loop structure that can be used to write the two most common looping structures: Do-While (Figure 1) and Repeat-Until (Figure 2). You can also use the Do-Loop structure for more complicated loops (see Figures 3 and 4).


Do While Condition1
    Body of Loop
  Loop Until Condition2

Figure 3. In True BASIC you can put conditions at both ends of the loop. Here, the body of the loop will be executed if the first condition is true. Following the body of the loop (if it is executed) the second condition will be tested. If it is false, the program will go back up and test the first condition again.


In standard BASIC, the If-Then-Else statement is limited in that only one statement can appear after the Then or Else. Some versions of BASIC permit multiple statements, but in many cases they must all be on the same line and separated by colons. In True BASIC, a block of statements can follow either the Then or the Else. True BASIC also includes If-Then-Elseif (Figure 5) and Select Case (Figure 6). The only provision for independent sections of a program (relatively speaking) in standard BASIC is the subroutine called by a Gosub and ending with a Return; in such a case, all the variables used in a subroutine are global. In True BASIC you may also use procedures and functions, either of which may be internal (using global variables) or external (using local variables). True BASIC also supports modules that let you create reusable units of code that you can incorporate into any program easily.


Do	 
    First Part of Body
    If Condition Then Exit Do
    Second Part of Body
 Loop

Figure 4. In this loop, a condition is tested in the middle of the body of the loop. If the condition is true, the program immediately exits the loop and resumes execution at the first statement after the loop (i.e. after the BASIC keyword ''Loop'').


Statements

The original BASIC didn't need graphics or sound, since no provisions for graphics or sound existed on its host computer. But as better computers have been developed, new statements have been added to BASIC to take advantage of new graphics and sound capabilities. Unfortunately, all too often, the commends differed from one machine to the next.

To solve this problem, the graphics and sound commands in True BASIC were made identical for all machines. With the graphics commands, you can draw points, lines, boxes and ellipses, you can color the interior of a closed figure, such as a box or ellipse and do 2D transformations, such as scaling, translation and rotation.

One nice feature of True BASIC is that the coordinate system is the same as that used in algebra: the horizontal axis runs from left to right and the vertical axis from bottom to top. (In most versions of BASIC, the vertical axis runs from top to bottom, with coordinate values increasing as you go down.

True BASIC also provides for windows whose size and location can be adjusted easily. While these windows are not as sophisticated as those created by GEM on the ST, they work the same way on all machines.


If Condition1 Then
       Block of Statements
    Elself Condition2 Then
       Block of Statements
    Elself Condttion 3 Then
       Block of Statements
    Else
       Block of Statements
    End If

Figure 5. An Elseif structure chooses which statements to execute based on the results of a number of possible tests. The example indicates three conditions that are tested, but any number of tests can be included.


Programming Environment

Using True BASIC, you'll notice several changes in the way you write BASIC programs. The most obvious is the inclusion of a powerful editor which features find, find and replace and block movement commands. The editor is GEM-based and uses pull-down menus and optional mouse-controlled cursor positioning.


Select Case Expression
  Case Value1
     Block of Statements
  Case Value2 TO Value3
     Block of Statements 
  Case Value4, Value5, Value6
     Block of Statements
  Case Is < 100
     Block of Statements
  Case Else
     Block of Statements
End Select  

Figure 6. If there are several tests, all based on the same expression, you can use a Case structure. You can test for a single value (the first Case), a range of values (the second Case), a list of values (the third Case), or a relative value (the fourth Case). A Case Else allows you to indicate what action to take if all of the tests are false.


Another big change is that you no longer need line numbers. This follows the trend seen in recent versions of BASIC. It's a welcome change for most programmers, although you may still use line numbers if you wish. In fact, the package includes one utility that numbers an unnumbered program and another that removes the line numbers from a numbered program. (In order to use the Goto or Gosub statements, the program must be numbered, but the other more powerful control structures eliminate the need for Gotos and Gosub's.) In our next True BASIC column, we'll take a closer look at three of True BASlCs most significant features: procedures, functions and modules.

Delmar Searls is the author of Grapher in the Fall 1987 issue of START


PRODUCTS MENTIONED

True BASIC language system and runtime, $99.95. True BASIC Inc., 12 Commerce Avenue, West Lebanon, NH 03784, {800) 872-2742.