[next] [previous] [contents]

  2.2 Creating and Running Programs
  Within the BASIC environment, there are two ways to cre-
  ate and edit a program. You can create and edit the program
  directly using line mode, or you can use the compiler com-
  mand EDIT to invoke a text editor when you are in the
  environment.

  The EDIT command invokes the default text editor for your
  system. After entering the BASIC environment, you can en-
  ter the EDIT command, create a program using a text editor,
  and then exit from the editor back to the environment. At
  this point, the program you created is the current program
  in memory, and you can type RUN or RUNNH to compile,
  link, and execute your program.



                                            Note

        RUNNH suppresses header information such as the
        name of the program and the time of day.

  You can also create a program using a text editor accessed
  from DCL. After creating the program, you can either use
  the OLD command from within the BASIC environment to
  read your program into memory, or compile your program
  from DCL.
Chapter 3 discusses how to compile programs
  from DCL.

  The following example shows a simple program that accepts
  three numbers entered at the terminal, averages them, and
  displays the result:
  $ BASIC
  BASIC V n.n
  Ready
  NEW FIRSTTRY

  Ready
  10 PRINT "Please enter three numbers"
              INPUT A, B, C
              PRINT "Their average is"; ( A + B + C ) / 3
              END
  RUNNH

  Output
  Please enter three numbers
  ? 5
  ? 10.3
  ? 4.7
  Their average is 6.66667
  Ready
  In the previous example, the DCL command BASIC places
  you in the BASIC environment. The environment command
  NEW informs BASIC that you want to create a new pro-
  gram and assigns the program a name. Here the program is
  named FIRSTTRY. If you do not enter a program name with
  the NEW command, BASIC assigns the name NONAME by
  default. The default file type is .BAS.

  The RUNNH command compiles, links, and executes the
  program you create. To save this program, enter the SAVE
  command at the Ready prompt.

  You can execute multiple-module programs while in the
  BASIC environment. To execute multiple-module programs,
  follow these steps:

  1. Compile all subprograms to generate object modules.
  2. Use the OLD command to read the main program into
        memory.
  3. Use the LOAD command to read the subprogram object
        modules into memory.
  4. Enter the RUN command.

  Figure 2-1 shows how to execute multiple-module pro-
  grams.

  The following example program contains multiple units:
  10 REM This program calls SUBPROGRAM SB1
  20 PRINT "NOW IN MAIN PROGRAM"
  30 CALL SB1
  40 PRINT "BACK IN MAIN PROGRAM"
  50 END
  10 SUB SB1
  20 PRINT "NOW IN SUBPROGRAM"
  30 SUBEND

  To execute this program in the BASIC environment, enter
  the following commands:
  Ready
  OLD SB1

  Ready
  COMPILE

  Ready
  OLD MAIN

  Ready
  LOAD SB1

  Ready
  RUN

  Output
  NOW IN MAIN PROGRAM
  NOW IN SUBPROGRAM
  BACK IN MAIN PROGRAM
  Ready
  If a STOP statement or Ctrl/C is encountered in a module
  other than the currently compiled module, VAX BASIC sig-
  nals ``Compiled procedure is currently not active''. At this
  point, you cannot use immediate mode statements.

  When you run multiple-module programs in the BASIC en-
  vironment, only one module is currently compiled. Normally,
  the currently compiled program is the one you read into
  memory with the OLD command. However, if a source
  file contains more than one program module, the last one
  (the one closest to the end of the source file) is the currently
  compiled module. In the previous example, MAIN is the
  currently compiled module.

  For more information about loading multiple object modules,
  see
Section 2.4.