HP 3000 Manuals

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


HP Business BASIC/XL Reference Manual

Variables 

In HP Business BASIC/XL, a variable can be numeric or string, scalar or
array, local parameter, or common.  This section explains declaring and
using variables.

Certain characteristics of variables can be changed in a program unit.
The OPTION and GLOBAL OPTION statements can change the following program
unit characteristics:

 *  Default numeric type.
 *  Initialization of numeric variables to zero.
 *  Implicit variable declaration.
 *  Default lower bound of arrays.
 *  Trace statement output control.
 *  Whether program main is the outer block for a multiprogram
    application.

The OPTION and GLOBAL OPTION statements are explained in chapter 4.

Variable Declaration 

A variable can be declared as local to one program unit or common to two
or more program units.  A local variable can be accessed only by the
program unit in which it is declared, whereas a common variable can be
accessed by every program unit that declares it.

A local variable can be declared explicitly by a variable declaration
statement, or implicitly the first time it is used.  A common variable
must be explicitly declared with the COM statement in every program unit
that uses it.

Table 3-9 lists the variable declaration statements and the
characteristics of the variables that they can declare.

          Table 3-9.  Variable Declaration Statements 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|       Variable Declaration Statement        |         Type of Variables Declared          |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| COM                                         | Any                                         |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| DIM                                         | Any                                         |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| SHORT INTEGER                               | Short Integer                               |
|                                             |                                             |
| SHORT INT                                   |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| INTEGER                                     | Integer                                     |
|                                             |                                             |
| INT                                         |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| SHORT REAL                                  | Short Real                                  |
|                                             |                                             |
| SHORT                                       |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| REAL                                        | Real                                        |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| SHORT DECIMAL                               | Short Decimal                               |
|                                             |                                             |
| SHORT DEC                                   |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| DECIMAL                                     | Decimal                                     |
|                                             |                                             |
| DEC                                         |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------

Variable declaration statements can appear anywhere in a program.  In the
interpreter, before the main procedure or function is executed, HP
Business BASIC/XL allocates space for both explicitly and implicitly
declared variables.  A variable cannot be explicitly declared more than
once in a program unit.

If a variable appears in a program line, but not in a declaration
statement, its name determines whether it is a numeric or string variable
and the context determines whether it is a scalar or an array.

Variable Names 

Table 3-10 gives examples of numeric and string variables names.

          Table 3-10.  Variable Names 

----------------------------------------------------------------------------------------------
|                              |                              |                              |
|        Variable Type         |        Variable Name         |           Examples           |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| Numeric                      | Identifier                   | Sum                          |
|                              |                              |                              |
|                              |                              | Grand_total                  |
|                              |                              |                              |
|                              |                              | X                            |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| String                       | Identifier with $ appended   | Name$                        |
|                              |                              |                              |
|                              |                              | Date1$                       |
|                              |                              |                              |
|                              |                              | A$                           |
|                              |                              |                              |
----------------------------------------------------------------------------------------------

A variable name is recognized throughout the program unit that declares
it.

Within a program unit, the following items can have the same name:

 *  Scalar numeric variable.
 *  Scalar string variable.
 *  Numeric array variable.
 *  String array variable.
 *  Line label.
 *  Common area name.

Context determines whether the name refers to a scalar variable, an array
variable or a line label.

Example 

The following are examples of declaring variables:

     100 INTEGER B      !Declares scalar numeric variable B
     110 INTEGER B(5)   !Declares numeric array variable B
     120 DIM B$[15]     !Declares scalar string variable B$
     130 DIM B$(3)[15]  !Declares string array variable B$
     140 B: STOP        !This line has a label, line label B
     150 PRINT B        !B refers to scalar numeric variable
     160 PRINT B(1)     !B refers to numeric array variable
     170 PRINT B$       !B$ refers to scalar string variable
     180 PRINT B$(3)    !B$ refers to string array variable
     190 GOTO B         !B refers to line label
     999 END

Numeric Variable Declaration Statements.  Each numeric variable
declaration statement explicitly declares one or more numeric scalar or
array variables.  The type of the variables depends on the statement.

Table 3-11 lists the numeric variable types, the number of bits used to
store the value, the range of each type, the precision of each type, and
the declaration statement that declares variables of that type.  HP
Business BASIC/XL accepts the character "D" as well as "E" to indicate
scientific notation.

          Table 3-11.  Numeric Variable Data Types 

----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
|  Numeric Type  |      Size      |            Range             |   Precision    |  Declaration   |
|                |   (in bits)    |                              |                |   Statement    |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
| Short integer  | 16             | [-32768, 32767]              | Exact          | SHORT INTEGER  |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
| Integer        | 32             | [-2147483648, 2147483647]    | Exact          | INTEGER        |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
| Short decimal  | 32             | [-9.99999 E63, -9.99999      | Exact (6       | SHORT DECIMAL  |
|                |                | E-63], 0, [9.99999 E-63,     | digits)        |                |
|                |                | 9.99999 E63]                 |                |                |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
| Decimal        | 64             | [-9.99999999999 E511,        | Exact (12      | DECIMAL        |
|                |                | -1.00000000000 E-511], 0,    | digits         |                |
|                |                | 1.00000000000 E-511,         |                |                |
|                |                | 9.99999999999 E511]          |                |                |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
| Short real     | 32             | [-3.40282 E38, -1.17549      | Not Exact (6   | SHORT REAL     |
|                |                | E-45], 0, [1.17549 E-45,     | digits)        |                |
|                |                | 3.40282 E38]                 |                |                |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------
|                |                |                              |                |                |
| Real           | 64             | [-1.79769313486231 E308,     | Not Exact (15  | REAL           |
|                |                | -4.94065645841247 E-324], 0, | digits         |                |
|                |                | [4.94065645841247 E-324,     |                |                |
|                |                | 1.79769313486231 E308]       |                |                |
|                |                |                              |                |                |
----------------------------------------------------------------------------------------------------

The syntax for each of these declaration statements is in chapter 4.

Array Variables.  An array is an ordered collection of variables of the
same type.  If the array elements are string variables, they have the
same maximum length.

An array element is legal wherever a scalar variable is legal.

An array variable is declared with a DIM, COM, or numeric declaration
statement.  The syntax for each of these is in chapter 4.

Implicit Declaration.  If a program unit does not contain an OPTION
DECLARE statement, its local variables can be declared implicitly, that
is, the first time they are used, rather than with a COM, DIM, or numeric
declaration statement.

Table 3-12 shows the characteristics that HP Business BASIC/XL gives to
implicitly declared variables.

          Table 3-12.  Characteristics of Implicitly Declared Variables 

----------------------------------------------------------------------------------------------
|                              |                              |                              |
|          Syntax of           |  Kind and Type of Variable   |       Size of Variable       |
|   First Variable Reference   |                              |                              |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| identifier                   | Scalar variable of default   | Not applicable               |
|                              | numeric type.                |                              |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| identifier(i1,...,in)        | Array variable of default    | Dimensions:n where 1<= n <=6 |
|                              | numeric type.                | Lower bound:  default Upper  |
|                              |                              | bound:  10                   |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| identifier$                  | Scalar string variable.      | Maximum length:  18          |
|                              |                              | characters                   |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| identifier$(i1,...,in)       | String array variable.       | Dimensions:  n where 1 <= n  |
|                              |                              | <= 6 Lower bound:  default   |
|                              |                              | Upper bound:  10 Maximum     |
|                              |                              | length of each element:  18  |
|                              |                              | characters                   |
|                              |                              |                              |
----------------------------------------------------------------------------------------------

Variable Initialization 

Before executing a program unit, HP Business BASIC/XL allocates space for
its local variables.  When HP Business BASIC/XL exits the program unit,
it deallocates local variable space.

Table 3-13 shows how and when HP Business BASIC/XL initializes local and
common variables.

          Table 3-13.  Variable Initialization 

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|                   |           Local Variable           |          Common Variable           |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| Initialized to    | Numeric:  zero.                    | Numeric:zero.                      |
|                   |                                    |                                    |
|                   | String:  null string.              | String:  null string.              |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| When              | Before HP Business BASIC/XL        | Before HP Business BASIC/XL        |
|                   | executes the program unit that     | executes the first program unit    |
|                   | declares the variable (for the     | that declares the variable.        |
|                   | main program unit, this is only    |                                    |
|                   | when a RUN or GET command is       |                                    |
|                   | executed).                         |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| How Often         | Each time HP Business BASIC/XL     | Once.                              |
|                   | executes that program unit.        |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| Unless            | OPTION NOINIT applies to that      | GLOBAL OPTION NOINIT was           |
|                   | program unit.                      | specified.                         |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

Variable Reference 

HP Business BASIC/XL can reference an entire scalar or array variable, a
single array element, or a substring of a string variable.  A substring
reference can be made to a scalar string variable or a string array
element.

Table 3-14 explains how to reference variables and variable parts, and
gives examples.

          Table 3-14.  Variable References 

-----------------------------------------------------------------------------------------------
|                       |                                             |                       |
|       Variable        |                Reference by                 |       Examples        |
|                       |                                             |                       |
-----------------------------------------------------------------------------------------------
|                       |                                             |                       |
| Scalar                | var_name                                    | X                     |
|                       |                                             |                       |
|                       |                                             | A$                    |
|                       |                                             |                       |
-----------------------------------------------------------------------------------------------
|                       |                                             |                       |
| Entire array          | var_name or var_name(*[,*]...)              | B(*), S$(*)           |
|                       |                                             |                       |
-----------------------------------------------------------------------------------------------
|                       |                                             |                       |
| Array element         | var_name(num_expr[,num_expr]...)            | B(1)                  |
|                       |                                             |                       |
|                       | One num_expr per dimension.                 | S$(2,4,6)             |
|                       |                                             |                       |
|                       | For each dimension, num_expr is in the      |                       |
|                       | range [lower_bound, upper_bound]            |                       |
|                       |                                             |                       |
-----------------------------------------------------------------------------------------------
|                       |                                             |                       |
| Substring *           | str_name[num_expr1,num_expr2]               | A$[1,5]               |
|                       |                                             |                       |
|                       | str_name[num_expr1;num_expr2]               | A$[5;3]               |
|                       |                                             |                       |
|                       | str_name[num_expr1]                         | S$[5]                 |
|                       |                                             |                       |
-----------------------------------------------------------------------------------------------

Table 3-14 Note 

*   If the substring reference belongs to a string array variable,
    str_name must be an array element reference.

Variable Assignment 

Numeric values must be assigned to numeric variables and string values
must be assigned to string variables.  A substring reference results in a
string value that can be assigned to a string variable.  Also, a string
value can be assigned to a substring on the left hand side of the
assignment statement.

Table 3-15 lists the types of values that can be assigned to variables.

          Table 3-15.  Possible Variable Assignments 

-----------------------------------------------------------------------------------------------
|                     |                                        |                              |
|      Variable       |        Can Be Assigned Value of        |           Example            |
|                     |                                        |                              |
-----------------------------------------------------------------------------------------------
|                     |                                        |                              |
| Numeric             | Numeric variable                       | A=B                          |
|                     | Numeric expression                     | A=(B+3)*(C/5)                |
|                     | Numeric literal                        | A=358                        |
|                     |                                        |                              |
-----------------------------------------------------------------------------------------------
|                     |                                        |                              |
| String              | String variable                        | A$=B$                        |
|                     | String expression                      | A$=B$+C$                     |
|                     | String literal                         | A$="abcde"                   |
|                     | Substring                              | A$=B$[1,10]                  |
|                     |                                        |                              |
-----------------------------------------------------------------------------------------------
|                     |                                        |                              |
| Substring           | String variable                        | A$[1,5]=C$                   |
|                     | String expression                      | A$[5]=C$+D$                  |
|                     | String literal                         | A$[1;3]="abc"                |
|                     | Substring                              | A$[1;3]=B$[1;3]              |
|                     |                                        |                              |
-----------------------------------------------------------------------------------------------

When a string value is assigned to a string variable, the length of the
string variable becomes the current length of the string value.  The
current length cannot exceed the maximum length of the string variable.

Several statements can assign values to variables.  They are the
following:

ACCEPT                       LENTER                       READ

ENTER                        LET                          TINPUT

INPUT                        LINPUT

Numeric Literals 

Numeric literals are real numbers or integers.

Syntax 

For literal integers (lit_integer):

digit[digit]

For literal real numbers:

lit_integer [.[lit_integer]][E[+,-]lit_integer] .lit_integer 

[E[+,-]lit_integer]

Parameters 

digit            A single digit 0..9.

lit_integer      A number consisting of any combination of the digits
                 0..9.

Examples 

          Table 3-16.  Examples of Numeric Literals 

-----------------------------------------------------------------------------------------
|                                                                                       |
|            Literal Integers                             Literal Real Numbers          |
|                                                                                       |
-----------------------------------------------------------------------------------------
|                                                                                       |
| 8                                              9.00                                   |
|                                                                                       |
| 123                                            35.9E+6                                |
|                                                                                       |
| 406903                                         .74E-3                                 |
|                                                                                       |
-----------------------------------------------------------------------------------------

A literal integer is stored as an integer or a short integer, depending
on the range required.

Context determines the data type used to store a literal fixed-point or
floating-point number.  A literal floating-point number is stored as a
real or decimal, depending on the precision required.

A literal that is beyond the range of the data type that it is to be
stored in is rounded.  If it is beyond the range of the largest data
type, an error occurs.

String Literals 

String literals are quoted string literals or special character string
literals.

Syntax 

Quoted string literal:

 {nonquote}
"{""      }..."

Special character string literal:

'integer 

Parameters 

nonquote         Nonquoted string literal.  Any character except a double
                 quote(").

integer          Special character string literal.  Must be in the range
                 [0,255].  Represents an ASCII character.

Examples 

The quoted string literals in the left column below are printed as shown
in the right column.  The fourth example is the null string.

          Table 3-17.  Examples of String Literals 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|               String Literal                |                   Printed                   |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| "cat"                                       | cat                                         |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| "black cat"                                 | black cat                                   |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| "12345"                                     | 12345                                       |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| ""                                          | Nothing                                     |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| """"                                        | "                                           |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| "say 'hi'"                                  | say 'hi'                                    |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| "say ""hi"""                                | say "hi"                                    |
|                                             |                                             |
---------------------------------------------------------------------------------------------

The following are special character string literals representing ASCII
characters

-----------------------------------------------------------------------------------------------
|                |                |                                                           |
|   Character    |    What It     |                           Note                            |
|                |   Represents   |                                                           |
|                |                |                                                           |
-----------------------------------------------------------------------------------------------
|                |                |                                                           |
| '0             | NUL            | null                                                      |
|                |                |                                                           |
-----------------------------------------------------------------------------------------------
|                |                |                                                           |
| '7             | BEL            | entry rings terminal's bell                               |
|                |                |                                                           |
-----------------------------------------------------------------------------------------------
|                |                |                                                           |
| '13            | CR             | carriage return                                           |
|                |                |                                                           |
-----------------------------------------------------------------------------------------------
|                |                |                                                           |
| '48            | 0              | zero                                                      |
|                |                |                                                           |
-----------------------------------------------------------------------------------------------

String Lengths 

Associated with every string variables is a maximum length and a current
length.  Table 3-18 explains the two types of length.  The units are the
number of eight bit characters.

          Table 3-18.  Maximum vs Current String Length 

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|                   |           Maximum Length           |           Current Length           |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| Definition        | Length of longest string value     | Length of string value that is     |
|                   | that can be assigned to string     | currently assigned to string       |
|                   | variable.                          | variable.                          |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| Range             | [1, 32767].                        | [0,curlength] where curlength is   |
|                   |                                    | current length.                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| Assigned          | Once, when string variable is      | Each time a value is assigned to   |
|                   | declared.                          | string variable.                   |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| Default           | 18 (for implicitly declared string | Zero (length of the null string).  |
|                   | variable).                         |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

When program execution begins in a main, procedure or function in which a
local string variable is declared either explicitly or implicitly and
OPTION INIT is active, the current length is initialized to zero.  The
effect of initializing a string variable to zero is to set the value of
the string to the null string.

Strings declared in a common area are initialized to the null string if
the INIT option is active when the main procedure or function that
contains the first occurrence of that common area begins execution.

Examples 

     100  DIM A$           !Maximum length of A$ is 18 by default
     110  DIM B$[5]        !Maximum length of B$ is 5
     120  A$="Cat"         !Current length of A$ is 3
     130  B$="Birds"       !Current length of B$ is 5
     140  C$="Elephants"   !Current length of C$ is 9, implicit definition
     150  A$="Caterpillar" !Now the current length of A$ is 11
     999  END

Substrings 

Substring Operations.  Substring operations are classified into two
types; references and assignments.  Substring references are
specifications of a string of characters that are to be extracted from a
string variable.  The value of the string with the substring reference is
never changed.  Substring references can occur alone on the right hand
side of assignment statements, in PRINT and PACK statements, and as
arguments to some built-in string functions, for example, UPC$.
Execution of a statement which contains a substring assignment results in
a possible change to the value of the string variable.  Substring
assignment can occur as the target of an assignment statement on the left
hand side, in INPUT, TINPUT, LENTER, and other input statements and in
the UNPACK statement.

Substring References.  A substring reference is a user-specified string
of characters that begins at a character specified by an index for a
string variable and has a length.  By definition, the index of the first
character in a string is one.  The length of a substring determines the
index of the last character in the string.  If the index of the
substring's last character in the string is greater than the actual
length of the string variable then spaces are added to the characters
referenced until a string of characters with the appropriate length is
built.

There are two methods for specifying the substring value to be
referenced.  The first is specification of the start index alone.  The
second is specification of the start index and either the index of the
last character or the length.

Start Index Only.  Syntax 

str_var[start]

Parameters 

str_var          A valid string variable name or string variable array
                 element reference.

Start            A numeric literal or expression that evaluates to a
                 value between 1 and LEN(str_var)+1, inclusive.

Example 

Consider the following substring reference:

     10  PRINT A$[Start]

The statement references the substring starting at the character at index
Start in the string, A$.  If LEN(A$) = 0 then the value is a null string.
Otherwise, it is that string beginning at character index start of A$ and
ending at character index LEN(A$).  (LEN is a function that returns the
length of a string.  It is described in chapter 5.)  If start =
(LEN(A$)+1) then the value is the null string.

Start Index and End Index or Length.  Syntax 

str_var[start,end] str_var[start;length]

Parameters 

str_var          A valid string variable name or string variable array
                 element reference.

start            A numeric literal or expression that evaluates to a
                 value between 1 and LEN(str_var)+1, inclusive.

end              A numeric literal or expression that evaluates to a
                 value between start-1 and 32767, inclusive.

length           A numeric literal or expression that evaluates to a
                 value between 0- and 32770, inclusive.

Example 

Consider the following two statements:

     10 PRINT A$[Start,End]
     20 PRINT A$[Start;Length]

Both statements reference the substring starting at the character at
index Start in the string, A$.

If End = (Start-1) or Length =0, then the value is the null string.

If Start = LEN(A$)+1), then the value is a string of (End-Start+1) or
Length spaces.

If End or (Start+Length-1) > MAXLEN(A$) then an error occurs.

For statement 10, if LEN(A$) >= End, then the value is the string
beginning at character index Start of A$ and ending at character index
End.  Otherwise, the value is all of the characters from character index
Start of A$ until character index LEN(A$) with spaces appended to the end
of the value for a total of (End-Start+1) characters.

For statement 20, if LEN(A$) >= (Start+Length-1) then the value is the
string beginning at character index Start of A$ and ending at character
index (Start+Length-1).  Otherwise, the value is all characters from
character index Start of A$ until character index LEN(A$) with spaces
appended to the end of the value for a total of Length characters.

     10 A$="basic"     !Substring values on the RHS of assignment
     20 B$=A$[1]       !Assigns "basic" to B$ - characters 1 to LEN(B$)
     30 B$=A$[2,3]     !Assigns "as" to B$ - characters 2,3
     40 B$=A$[2;3]     !Assigns "asi" to B$ - characters 2,3,4
     50 B$=A$[4,7]     !Assigns "ic  " to B$ - characters 4,5 + 2 spaces
     60 B$=A$[6;2]     !Assigns "  " to B$ - a null string + 2 spaces
     70 B$=A$[7,10]    !Range error because 7 > LEN(A$)+1

Substring Assignment.  A substring assignment begins at a user-specified
index corresponding to a character position in a string variable and has
a length.  By definition, the index of the first character in a string is
one.  The length of the substring determines the index of the last
character in the string to which a value is assigned.  If the number of
characters assigned to the string is less than the length of the
substring specified, then spaces are assigned to the remaining characters
in the string variable until the number of characters assigned is equal
to the length of the substring.

There are two methods for specifying the target substring.  The first is
the specification of the starting index alone, and the second is
specification of the starting index and either the index of the last
character or the length.

Start Index Only.  Syntax 

str_var[start]

Parameters 

str_var          A valid string variable name or string variable array
                 element reference.

start            A numeric literal or expression that evaluates to a
                 value between 1 and LEN(str_var)+1, inclusive.

Example 

Consider the following assignment statement:

     10  A$[Start]=B$

Execution of this statement assigns the value of B$ to A$ beginning at
character Start.

If Start= (LEN(A$)+1), then a string append is done.

If the LEN of the string following assignment is greater than that before
assignment, then the actual length of A$ is reset.

If (Start+LEN(B$)-1) <= MAXLEN(A$), then the value of B$ is assigned to
A$.  Otherwise, (MAXLEN(A$)-Start+1) characters from the value of B$ are
assigned to A$.

Note that as long as 1 <= Start <= LEN(A$)+1, then regardless of the
length of B$, no bounds violation occurs during the string assignment.

Start Index and End Index or Length.  Syntax 

str_var[start,end] str_var[start;length]

Parameters 

str_var          A valid string variable name or string variable array
                 element reference.

start            A numeric literal or expression that evaluates to a
                 value between 1 and LEN(str_var)+1, inclusive.

end              A numeric literal or expression that evaluates to a
                 value between start-1 and 32767, inclusive.

length           A numeric literal or expression that evaluates to a
                 value between 0- and 32767, inclusive.

Example 

Consider the following two assignment statements:

     10 A$[Start,End]=B$
     20 A$[Start;Length]=B$

Execution of either of these statements assigns the value of B$ to A$
beginning at character Start.

If Start = (LEN(A$)+1) then a string append is done.

If the LEN of the string after the assignment is greater than that before
assignment then the actual length of A$ is reset.

If LEN(B$) >= (End-Start+1) or Length then the number of characters from
B$ assigned to A$ is equal to (End-Start+1) or Length, respectively.  If
LEN(B$) < (End-Start+1) or Length, then the value of B$ is assigned to A$
beginning at character position Start.  Spaces assigned to each remaining
character in A$ up to and including the character with index End or until
a total of Length characters has been assigned.

If End or (Start+Length-1) > MAXLEN(A$), then a bounds violation occurs.

     10 B$="basic"       !Assigns a value to B$
     20 A$[1]=B$         !Value of A$ is "basic"
     30 A$[2,6]=B$       !Value of A$ is now "bbasic"
     40 A$[1;5]=B$       !Value of A$ is now "basicc"
     50 A$[4,6]=B$       !Value of A$ is now "basbas"
     60 A$[7]=B$         !Value of A$ is "basbasbasic" - string append
     70 A$[1,6]=B$       !Value of A$ is "basic basic" - 1 space was assigned
     80 A$[13;5]=B$      !Range error because 13 &> LNE(A$)+1
     90 A$[LEN(A$)+1]=B$ !Value of A$ is "basic basicbasic" - string append



MPE/iX 5.0 Documentation