HP 3000 Manuals

Creation and Modification Commands [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

Creation and Modification Commands 

To add a line to the current program, respond to the HP Business BASIC/XL
interpreter prompt (>) as follows:

   1.  Type the line number followed by the rest of the program line.  To
       continue the program line on the next physical line, end the line
       with a continuation character (&).  In response to the
       continuation prompt (>>), type the rest of the line.
   2.  Press RETURN.

If the program already has a line with the same number as the new line,
the new line replaces that line; if not, the new line is added to the
program.

If the line is syntactically incorrect, HP Business BASIC/XL prints an
error message.  Correct the line by entering a line with the same line
number or by using the REDO command.  REDO is explained later in this
chapter.

Follow these steps to delete a single program line:

   1.  Type its line number.
   2.  Press RETURN.

The DELETE command or statement deletes both individual program lines and
groups of program lines.

Example 

The following example shows adding and deleting lines:

     >10 INTEGER A,B       !Add line 10 to program
     >20 REAL C,D,E,F,G,&   !Add line 20 to program with continuation characters
     >>H,I,J,K             !Complete line 20
     >10 INTEGER X,Y,Z     !Replace line 10
     >30 REAL C            !Redeclare C
     >RUN                  !Error occurs at line 30
     Error 12 in line 30
     Attempt to redeclare a variable, C, in line 30.
     VERIFY Error(s) in program.
     >30 REAL N            !Correct error
     >20                   !Delete line 20
     >LIST 
         10 INTEGER X,Y,Z
         30 REAL N
     >

Table 2-3 lists the commands used to create and modify programs.  The
DELETE and SECURE commands can also be statements; the others are
commands only.  All of the commands or statements in Table 2-3 affect the
current program.  None are compilable.

          Table 2-3.  Program Creation and Modification Commands 

---------------------------------------------------------------------------------------------
|                   |                                                                       |
|      Command      |                                Result                                 |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| AUTO              | Automatically types the line number of the next program line you are  |
|                   | adding.                                                               |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| CHANGE            | Changes one string to another, in all or part of the program.         |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| COPY              | Copies one or more program lines.                                     |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| DELETE            | Deletes all or part of a program.                                     |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| FIND              | Finds and lists occurrences of a string in all or part of a program.  |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| INDENT            | Indents the bodies of constructs relative to the statements that      |
|                   | define them.                                                          |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| LIST *            | Lists all or part of a program.                                       |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| LIST SUBS         | Lists the names and starting line numbers of all subunits in the      |
|                   | program, and indicates the program unit that contains the currently   |
|                   | executing program line.                                               |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| MODIFY            | Replaces, deletes, or inserts characters in one or more program       |
|                   | lines.                                                                |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| MOVE              | Moves one or more program lines.                                      |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| NAME              | Names or renames the current program.                                 |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| REDO              | Redisplays the last line entered, and allows you to change it.        |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| RENUMBER          | Renumbers program lines.                                              |
|                   |                                                                       |
---------------------------------------------------------------------------------------------
|                   |                                                                       |
| SECURE            | Prevents part or all of a program from being listed or modified.      |
|                   |                                                                       |
---------------------------------------------------------------------------------------------

Table 2-3 Note 

*   Sends output to the system printer or other device (specified by the
    SEND SYSTEM OUTPUT TO statement, explained in chapter 4).

A subunit can only be added or moved between two program units.  Once the
DEF or SUB statement is entered, the statements in the multi-line
function or subunit can be added immediately following.  An error will
occur if you try to delete either a DEF or SUB statement from a subunit
defined in a program.

Example 

The following shows where functions and subroutines can be placed.  Note
that the example illustrates the structure of a program but is not an
executable program.

     10 REM Main program begins
          .
          .
          .
     99 END
          .
          .
          .
     (DEF or SUB statement can be put here)
          .
          .
          .
     200 DEF...
          .
          .
          .
     250 FNEND
          .
          .
          .
     (DEF or SUB statement can be put here)
          .
          .
          .
     300 SUB...
          .
          .
          .
     (DEF or SUB statement cannot be put here!)
          .
          .
          .
     350 SUBEND
          .
          .
          .
     (DEF or SUB statement can be put here)

Line-Continuation Character:  & 

The ampersand (&) is the line-continuation character.  When it is typed
at the end of a physical line (that is, a line on the terminal screen),
it tells HP Business BASIC/XL that the program line continues on the next
physical line.

The length of a physical line is determined by the terminal (it is
usually 80 characters).  HP Business BASIC/XL allows you to type as many
as 500 characters before pressing RETURN. If you type more characters
than the number that fit on one line of the terminal screen, HP Business
BASIC/XL prints the extra characters on the next physical line.

When a program line that was typed with continuation characters is listed
on a terminal screen, the continuation characters are not necessarily
printed in their original positions.

A line of fewer than 500 characters can contain more than 500 characters
when it is changed to standard format.  If it does, an error occurs and
HP Business BASIC/XL lists the line with "*" at the end.

AUTO Command 

The AUTO command supplies automatic line numbering.  That is, it replaces
the HP Business BASIC/XL interpreter prompt (>) with the line number of
the next program line.  AUTO supplies line numbers until automatic line
numbering is terminated.  The AUTO command is a command-only statement.
That is, it can only be issued at the interpreter prompt and cannot be
placed in a program.

Syntax 

     AUTO [line_num [, num_expr] ]

Parameters 

line_num         First line number to be displayed.  Default is the
                 number of the last program line entered, plus 10.  If
                 previous program lines have not been entered, line_num 
                 is 10.  An error occurs if line_num is illegal.

num_expr         Increment.  If last line number displayed was n, the
                 next line number to be displayed is n+num_expr.  The
                 increment is set to 10 if this value is not supplied.

The automatically generated line number is blank padded on the left with
one blank and then right-justified in the next six columns.  Column 8 is
left as a blank and the cursor appears in the ninth column.  If the line
number exceeds 999999, automatic line-numbering ends.

To terminate automatic line-numbering, do one of the following:

 *  Type "//" at the beginning of a line and press RETURN 
 *  Type CONTROL Y anywhere on a line (this erases all typing on the
    line)

When AUTO is terminated, the prompt returns to ">".

Examples 

     >AUTO 30        !Start automatic line numbering at line 30
          30  _

Command          Numbers Generated 

AUTO             10, 20, 30, 40,...
AUTO 100         100, 110, 120, 130,...
AUTO 100,5       100, 105, 110, 115,...
AUTO 500,50      500, 550, 600, 650,...

CHANGE Command 

The CHANGE command finds every occurrence of a specified string in all or
part of the program and changes it to a new string.  The VERIFY option
allows you to control which occurrences within a program will be changed.
The CHANGEQ form of the command suppresses the printing of changed lines
to the terminal.  The CHANGE command is a command-only statement.  That
is, it can only be issued at the interpreter prompt and cannot be placed
in a program.

Syntax 

{CHANGE [VERIFY]}
{CHANGEQ        } str_expr1 TO str_expr2 IN line_range_list 

{CHANGE }
{CHANGEQ} from_name [()] TO to_name [()] IN subunit_name_list 

Parameters 

VERIFY                          Before modifying a line, the CHANGE
                                command displays the line, with a caret
                                (^) indicating the position of str_expr1,
                                and asks the question:

                                Change this occurrence? (Yes/No/Exit)   Y

                                To approve the change, do one of the
                                following:
                                 *  Press RETURN 
                                 *  Type Y or Yes and press RETURN 

                                To cancel the change in that line and
                                continue the CHANGE command:
                                 *  Type N or No and press RETURN 

                                To cancel the change in that line and
                                stop the CHANGE command:
                                 *  Type E or Exit and press RETURN 

str_expr1                       Quoted string to be changed.

str_expr2                       Quoted replacement string.

from_name                       Any numeric or string identifier.  If
                                followed by "()", the identifier
                                represents an array.  Without "()", that
                                identifier represents a numeric or string
                                scalar identifier.

to_name                         The new name of the identifier.  This
                                name may exist already.  If "()" follows
                                the to_name, the new name will be an
                                array.  If from_name specifies an array,
                                the to_name also represents an array,
                                even if "()" is not specified.  The
                                to_name can not be an array if from_name 
                                is a scalar.

subunit_name_list               List of subunits in which the change will
                                occur.  Valid names are:

                                     SUB name 
                                     name 
                                     MAIN
                                     ALL

                                where {name} represents the name of any
                                subunit or multi-line function.

line_range_list                 The list of lines to be changed.  Refer
                                to "Specifying Line Ranges" earlier in
                                this chapter for syntax.

The from_name form of CHANGE cannot change a scalar to an array or vice
versa.  Names can be changed on a subunit basis only (as opposed to line
by line when using quoted strings) and VERIFY is not available.

If changing str_expr1 to str_expr2 would make a line too long or cause a
syntax error, the CHANGE command stops, displaying the line and an error
message.  The line does not change.

Examples 

The following example shows the CHANGE command.  In this example, the
array A is changed to Array1 throughout the program, B$ is changed to
Array2$ throughout the program, and I is changed to Loop_control_var in
lines 50 through 110.

     >LIST 
          10 DIM A(5),B$(2,4)[2]
          20 INTEGER X,Y,Z
          30 FOR I=1 TO 5
          40   A(I)=I
          50 NEXT I
          60 FOR I=1 TO 2
          70   FOR J=1 TO 4
          80     B$(I,J)=CHR$(I) + CHR$(J)
          90   NEXT J
         100 NEXT I
         110 I=7
         120 PRINT I
         999 END
     >CHANGE "A" TO "Array1" IN ALL 
          10 DIM Array1(5), B$(2,4)[2]
          40   Array1(I)=I
     >CHANGEQ "B$" TO "Array2$" IN ALL 
     >CHANGE VERIFY "I" TO "Loop_control_var" IN 50/110 
          50 NEXT I
                  ^
      Change this occurrence? (Yes/No/Exit)   N RETURN 
          60 FOR I=1 TO 2
                 ^
      Change this occurrence? (Yes/No/Exit)   Y RETURN 
          60 FOR Loop_control_var=1 TO 2
          80     Array2$(I,J)=CHR$(I) + CHR$(J)
                         ^
      Change this occurrence? (Yes/No/Exit)   Y RETURN 
          80     Array2$(Loop_control_var,J)=CHR$(I)+CHR$(J)
                                                  ^
      Change this occurrence? (Yes/No/Exit)   Y RETURN 
          80     Array2$(Loop_control_var,J)=CHR$(Loop_control_var)+CHR$(J)
         100 NEXT I
                  ^
      Change this occurrence? (Yes/No/Exit)   Y RETURN 
         100 NEXT Loop_control_var
         110 I=7
             ^
      Change this occurrence? (Yes/No/Exit)   E RETURN 
     >LIST 
          10 DIM Array1(5), Array2$(2,4)[2]
          20 INTEGER X,Y,Z
          30 FOR I=1 TO 5
          40   Array1(I)=I
          50 NEXT I
          60 FOR Loop_control_var=1 TO 2
          70   FOR J=1 TO 4
          80     Array2$(Loop_control_var,J)=CHR$(Loop_control_var)+CHR$(J)
          90   NEXT J
         100 NEXT Loop_control_var
         110 I=7
         120 PRINT I
         999 END

     >LIST 
        10 I=10
        20 PRINT "HELLO"
        30 I_to_J = 6
       100 SUB I
       110 SHORT INTEGER I
       120 I=7
       130 I_abc=8
       140 SUBEND
     >CHANGE "I" to "K" IN ALL 
        10 K=10
        20 PRKNT "HELLO"
           ^
        Syntax error at character 15
        Statement needs =
     >CHANGE I TO LOOP IN ALL 
       100 SUB Loop
       110 SHORT INTEGER Loop
       120 Loop=7

COPY and MOVE Commands 

The COPY command copies one or more program lines to a specified
location.  The MOVE command moves one or more program lines to a
specified location and then deletes the original lines.  The COPY and
MOVE commands are command-only statements.  That is, they can only be
issued at the interpreter prompt and can not be placed in a program.  The
COPYQ and MOVEQ forms of the commands suppress the printing of the copied
or moved lines to the terminal.

If the lines are moved to a location that is between lines that already
exist in the program, there must be enough room in that location for all
the lines.

Syntax 

{COPY }            {TO}
{COPYQ} line_range {, } line_num 

{MOVE }            {TO}
{MOVEQ} line_range {, } line_num 

Parameters 

line_range       Lines to be copied or moved.

line_num         Line number for first copied or moved line, after it is
                 copied or moved.  Cannot be in line_range.

Examples 

The following examples show the use of the COPY and MOVE commands.  Lines
10 and 20 are both moved to another location, and line 30 is copied both
to line 60 and line 80.  That illustrates that the COPY command does not
delete the original line, but the MOVE command does.

     >10 PRINT "Line 10" 
     >20 PRINT "Line 20" 
     >30 PRINT "Line 30" 
     >MOVE 10 TO 40 
             40 PRINT "Line 10"
     >MOVEQ 20 TO 50 
     >LIST 
             30 PRINT "Line 30"
             40 PRINT "Line 10"
             50 PRINT "Line 20"
     >COPY 30/40 TO 60 
             60 PRINT "Line 30"
             70 PRINT "Line 10"
     >COPYQ 30 TO 80 
     >LIST 
             30 PRINT "Line 30"
             40 PRINT "Line 10"
             50 PRINT "Line 20"
             60 PRINT "Line 30"
             70 PRINT "Line 10"
             80 PRINT "Line 30"

DELETE Statement 

The DELETE statement deletes all or part of a program.

Syntax 

{DELETE}
{DEL   } line_range_list 

Parameters 

line_range_list     The list of lines to be deleted.  See "Specifying
                    Line Ranges" earlier in this chapter for syntax.

The DELETE statement deletes the lines that line_range_list specifies.
The DELETE statement deletes itself only if it belongs to the last
line_range.

If the DELETE statement deletes a SUB or DEF statement, it must delete
the entire subunit that the SUB or DEF statement defines.

If line_range_list includes a busy line or a busy subunit, an error
occurs and no lines are deleted (see "Busy Lines and Busy Subunits" in
the "Program Debugging" section of this chapter for the definition of
busy).

Example 

The following example shows the use of DELETE. Lines 20, 25, 40, and 50
are all deleted.

     >LIST 
         10 INTEGER A,B
         20 REAL C
         25 REAL D
         30 LET A,B=0
         40 LET C=2*PI
         50 LET D=PI/180
         99 END
     >DELETE 20/25,40/50 
     >LIST 
         10 INTEGER A,B
         30 LET A,B=0
         99 END
     >

FIND Command 

The FIND command finds and lists all occurrences of a specified
identifier or string literal in all or part of the program.

The FIND command with the identifier specified finds all occurrences of
the variable in the given line ranges.  Only occurrences of the specific
variable are listed.  This type of FIND command is useful when an
identifier name occurs as part of a quoted string literal, or is an
embedded string in the name of another identifier.

Syntax 

     FIND identifier  [ ()]  [ IN line_range_list ] FIND str_expr [IN line_range_list]

Parameters 

identifier                Any numeric or string variable.  If followed by
                          "()", then the identifier represents an array.

str_expr                  A string expression that evaluates to a string
                          literal.

line_range_list           The lines that FIND is to look in for the
                          specified string .  The syntax is described in
                          "Specifying Line Ranges" earlier in this
                          chapter.

To stop the FIND command, press CONTROL Y.

Examples 

The following example shows the use of the FIND command.  It shows first
finding string literals ("Array" and "Array2") and then shows finding the
identifier "I".

     >LIST 
        100 DIM Array1(15), Array2(15)
        110 FOR I=1 TO 15
        120   Array1 = I*I
        130   Array2 = I+I
        140 NEXT I
        150 PRINT Array1(*), Array2(*)
        999 END
     >FIND "Array" IN ALL 
        100 DIM Array1(15), Array2(15)
        120   Array1 = I*I
        130   Array2 = I+I
        150 PRINT Array1(*), Array2(*)
     >FIND "Array2" IN 100/140 
        100 DIM Array1(15), Array2(15)
        130   Array2 = I+I
     >FIND I 
        110 FOR I=1 TO 15
        120   Array1 = I*I
        130   Array2 = I+I
        140 NEXT I
     >



MPE/iX 5.0 Documentation