HP 3000 Manuals

LET [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

LET 

The LET statement assigns a value to one or more variables.

Syntax 

      {num_var [, num_var]...= num_expr}
[LET] {str_var [, str_var]...= str_expr}

Parameters 

num_var          Numeric variable(s) that the value of num_expr is/are
                 assigned.

str_var          String variable(s) that the value of str_expr is/are
                 assigned.

num_expr         Value that num_var will contain.  This can be either a
                 literal, or an expression.

str_expr         Value that str_var will contain.  This can be either a
                 literal or an expression.

Examples 

     10 LET Number=3                  !Assignment:  3, to Number
     20 Num1, Num2, Num3=4+6          !Assignment:  10, to Num1, Num2, and Num3
     30 String$="cat"                 !Assignment:  "cat" to String$
     40 LET Str1$,Str2$= "Ab" + "CdE" !Assignment:  "AbCdE", to Str1$, and Str2$

HP Business BASIC/XL accesses variables in LET statements from left to
right.  If variables have not been declared, and implicit declaration is
illegal, an error occurs.  If no error occurs, HP Business BASIC/XL
evaluates the expression and assigns its value to the variables, from
right to left.  If the value is numeric, HP Business BASIC/XL converts it
to the type of each of the variables prior to assigning it to the
variables.

     10 OPTION NODECLARE    !Implicit declaration is legal
     20 OPTION REAL         !Default numeric type is real
     30 INTEGER A           !Integer A is explicitly declared
     40 DECIMAL B           !Decimal B is explicitly declared
     50 LET A,B,C=(5+4)*3   !Real C is implicitly declared
     99 END

In line 50, HP Business BASIC/XL does the following:

 *  Accesses A, B, and C in that order
 *  Evaluates (5+4)*3
 *  Assigns the following values in the following order:

    To:              The Value: 

    C                real 27.0
    B                decimal 27.0
    A                integer 27

When HP Business BASIC/XL converts a numeric value to a numeric variable
type that has fewer significant digits than the value does, it rounds the
value first.  An error occurs if the value is outside the range of the
variable type.  An error also occurs if an assigned string value is too
long for it's string variable (that is, if the length of the string value
exceeds the maximum length of the string variable).

If an assignment statement has more than one variable to the left of the
equal sign, for example; A,B,C=5, and an error occurs in the middle of
the assignment statement, the variables after (or to the right of) the
error contain the new value.  The variables before (or to the left of)
the error do not.  The variable in which the error occurred does not
contain a new value.

In the example below, an error occurs when 80,000 is assigned to C in
line 30 (C, a short integer can have a maximum value of 32767).  D and E
are assigned the value 80,000, but A, B, and C still have the value zero
following the error.

     10 SHORT INTEGER C
     20 A,B,C,D,E=0
     30 A,B,C,D,E=80000
     99 END

Multiple Assignment Statement 

The multiple assignment statement is a series of LET statements,
separated by semicolons.  The LET keyword can only appear in the first
LET statement.

Syntax 

LET_stmt [; LET_stmt]...

Parameters 

LET_stmt         A LET statement

Example 

     10 LET A,B=5; C$="HI";D=4+2



MPE/iX 5.0 Documentation