 |
Compaq BASIC for OpenVMS Alpha and VAX
Systems Reference Manual
Example 1
!Numeric Initialization
MAT CONVERT = zer(10,10)
|
Example 2
!Initialization
MAT na_me$ = NUL$(5,5)
|
Example 3
!Array Arithmetic
MAT new_int = old_int - rslt_int
|
Example 4
!Scalar Multiplication
MAT Z40 = (4.24) * Z
|
Example 5
!Inversion and Transposition
MAT Q% = INV (Z)
|
MAT INPUT
The MAT INPUT statement assigns values from a terminal or
terminal-format file to array elements.
Format
Syntax Rules
- Chnl-exp is a numeric expression that specifies a channel
number associated with a file. It must be immediately preceded by a
number sign (#).
- The file associated with chnl-exp must be an open
terminal-format file or terminal. If chnl-exp is not
specified, BASIC takes data from the controlling terminal.
- Int-exp1 and int-exp2 define the upper bounds of
the array being implicitly created or the dimensions of an existing
array.
- If you are creating an array, int-exp1 and
int-exp2 cannot exceed 10.
Remarks
- You cannot use the MAT INPUT statement on arrays of more than two
dimensions.
- You cannot use the MAT INPUT statement on arrays of data type
DECIMAL or on arrays named in a RECORD statement.
- All arrays specified with the MAT INPUT statement must have lower
bounds of zero.
- If you do not specify bounds, BASIC creates the array and
dimensions it to (10,10).
- If you do specify upper bounds, BASIC creates the array
with the specified bounds. If the bounds exceed (10) or (10,10),
BASIC signals "Redimensioned array" (ERR=105).
- To use the MAT INPUT statement with arrays larger than (10,10),
create the input and output arrays with the DIM statement.
- When the array exists, the following rules apply:
- If you specify bounds, BASIC redimensions the array to the
specified size. However, MAT INPUT cannot increase the total number of
array elements.
- If you do not specify bounds, BASIC does not redimension
the array.
- For terminals open on channel zero only, the MAT LINPUT statement
prompts with a question mark (?) unless a SET NO PROMPT statement has
been executed. See the description of the SET PROMPT statement for more
information.
- Use commas to separate data elements and a line terminator to end
the input of data. Use an ampersand (&) before the line terminator
to continue data over more than one line.
- The MAT INPUT statement assigns values by row. For example, it
assigns values to all elements in row 1 before beginning row 2.
- The MAT INPUT statement assigns the row number of the last data
element transferred into the array to the system variable NUM.
- The MAT INPUT statement assigns the column number of the last data
element transferred into the array to the system variable NUM2.
- If there are fewer elements in the input data than there are array
elements, BASIC does not change the remaining array elements.
- If there are more data elements in the input stream than there are
array elements, BASIC ignores the excess.
- Row zero and column zero are not changed.
- For information about graphics input in VAX BASIC, see the MAT
LOCATE and the MAT GET statements in Programming with VAX BASIC Graphics.
Example
MAT INPUT XYZ(5,5)
MAT PRINT XYZ;
|
Output
? 1,2,3,4,5
1 2 3 4 5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
|
MAT LINPUT
The MAT LINPUT statement receives string data from a terminal or
terminal-format file and assigns it to string array elements.
Format
Syntax Rules
- Chnl-exp is a numeric expression that specifies a channel
number associated with a file or terminal. It must be immediately
preceded by a number sign (#).
- The file associated with chnl-exp must be an open
terminal-format file or terminal. If a channel is not specified,
BASIC takes data from the controlling terminal.
- Int-exp1 and int-exp2 define the upper bounds of
the array being implicitly created or the dimensions of an existing
array.
- If you are creating an array, int-exp1 and
int-exp2 cannot exceed 10.
Remarks
- You cannot use the MAT LINPUT statement on arrays of more than two
dimensions.
- You cannot use the MAT LINPUT statement on arrays of data type
other than STRING or on arrays named in a RECORD statement.
- If you do not specify bounds, BASIC creates the array and
dimensions it to (10,10).
- If you do specify upper bounds, BASIC creates the array
with the specified bounds. If the bounds exceed (10) or (10,10),
BASIC signals "Redimensioned array" (ERR=105).
- All arrays specified with the MAT LINPUT statement must have lower
bounds of zero.
- To use MAT LINPUT with arrays larger than (10,10), create the input
arrays with the DIM statement.
- When the array exists, the following rules apply:
- If you specify bounds, BASIC redimensions the array to the
specified size. However, MAT LINPUT cannot increase the total number of
array elements.
- If you do not specify bounds, BASIC does not redimension
the array.
- For terminals open on channel zero only, the MAT LINPUT statement
prompts with a question mark (unless a SET NO PROMPT statement has been
executed) for each string array element, starting with element (1,1).
BASIC assigns values to all elements of row 1 before beginning
row 2.
- The MAT LINPUT statement assigns the row number of the last data
element transferred into the array to the system variable NUM.
- The MAT LINPUT statement assigns the column number of the last data
element transferred into the array to the system variable NUM2.
- Typing only a line terminator in response to the question mark
prompt causes BASIC to assign a null string to that string
array element.
- MAT LINPUT does not change row and column zero.
Example
DIM cus_rec$(3,3)
MAT LINPUT cus_rec$(2,2)
PRINT cus_rec$(1,1)
PRINT cus_rec$(1,2)
PRINT cus_rec$(2,1)
PRINT cus_rec$(2,2)
|
Output
? Babcock
? Santani
? Lloyd
? Kelly
Babcock
Santani
Lloyd
Kelly
|
MAT PRINT
The MAT PRINT statement prints the contents of a one- or
two-dimensional array on your terminal or assigns the value of each
array element to a record in a terminal-format file.
Format
Syntax Rules
- Chnl-exp is a numeric expression that specifies a channel
number associated with a file or terminal. It must be immediately
preceded by a number sign (#).
- The file associated with chnl-exp must be an open
terminal-format file or terminal. If you do not specify a channel,
BASIC prints data on the controlling terminal.
- Int-exp1 and int-exp2 define the upper bounds of
the array being implicitly created or the dimensions of an existing
array.
- The separator (comma or semicolon) determines the output format for
the array.
- If you use a comma, BASIC prints each array element in a
new print zone and starts each row on a new line.
- If you use a semicolon, BASIC separates each array element
with a space and starts each row on a new line.
- If you do not use a separator character, BASIC prints each
array element on its own line.
Remarks
- You cannot use the MAT PRINT statement on arrays of more than two
dimensions.
- You cannot use the MAT PRINT statement on arrays of data type
DECIMAL or on arrays named in a RECORD statement.
- When you use the MAT PRINT statement to print more than one array,
each array name except the last must be followed with either a comma or
a semicolon. BASIC prints a blank line between arrays.
- If the array does not exist, the following rules apply:
- If you do not specify bounds, BASIC creates the array and
dimensions it to (10,10).
- If you specify upper bounds, BASIC creates the array with
the specified bounds. If the bounds exceed (10) or (10,10),
BASIC prints the elements (1) through (10) or (1,1) through
(1,10) and signals "Subscript out of range" (ERR=55).
- All arrays specified with the MAT PRINT statement must have lower
bounds of zero.
- When the array exists, the following rules apply:
- If the specified bounds are smaller than the maximum bounds of a
dimensioned array, BASIC prints a subset of the array, but
does not redimension the array. For example, if you use the DIM
statement to dimension A(20,20), and then MAT PRINT A(2,2),
BASIC prints elements (1,1), (1,2), (2,1), and (2,2) only;
array A(20,20) does not change.
- If you do not specify bounds, BASIC prints the entire
array.
- The MAT PRINT statement does not print elements in row or column
zero.
- The MAT PRINT statement cannot redimension an array.
Example
DIM cus_rec$(3,3)
MAT LINPUT cus_rec$(2,2)
MAT PRINT cus_rec$(2,2)
|
Output
? Babcock
? Santani
? Lloyd
? Kelly
Babcock
Santani
Lloyd
Kelly
|
MAT READ
The MAT READ statement assigns values from DATA statements to array
elements.
Format
Syntax Rules
- Int-exp1 and int-exp2 define the upper bounds of
the array being implicitly created or the dimensions of an existing
array.
- If you are creating an array, int-exp1 and
int-exp2 cannot exceed 10.
Remarks
- If you do not specify bounds, BASIC creates the array and
dimensions it (10,10).
- If you specify bounds, BASIC creates the array with the
specified bounds. If the bounds exceed (10) or (10,10), BASIC
signals "Redimensioned array" (ERR=105).
- To read arrays larger than (10,10), create the array with the DIM
statement.
- All arrays specified with the MAT statement must have lower bounds
of zero.
- When the array exists, the following rules apply:
- If you specify upper bounds, BASIC redimensions the array
to the specified size. However, MAT READ cannot increase the total
number of array elements.
- If you do not specify bounds, BASIC does not redimension
the array.
- All the DATA statements must be in the same program unit as the MAT
READ statement.
- The MAT READ statement assigns data items by row. For example, it
assigns data items to all elements in row 1 before beginning row 2.
- The MAT READ statement does not read elements into row or column
zero.
- The MAT READ statement assigns the row number of the last data
element transferred into the array to the system variable, NUM.
- The MAT READ statement assigns the column number of the last data
element transferred into the array to the system variable, NUM2.
- You cannot use the MAT READ statement on arrays of more than two
dimensions.
- You cannot use the MAT READ statement on arrays of data type
DECIMAL or on arrays named in a RECORD statement.
Example
MAT READ A(3,3)
MAT READ B(3,3)
PRINT
PRINT "Matrix A"
PRINT
MAT PRINT A;
PRINT
PRINT "Matrix B"
PRINT
MAT PRINT B;
DATA 1,2,3,4,5,6
|
Output
Matrix A
1 2 3
4 5 6
0 0 0
Matrix B
0 0 0
0 0 0
0 0 0
|
MAX
The MAX function compares the values of two or more numeric expressions
and returns the highest value.
Format
Syntax Rules
BASIC allows you to specify up to eight numeric expressions.
Remarks
- If you specify values with different data types, BASIC
performs data type conversions to maintain precision.
- BASIC returns a function result whose data type is
compatible with the values you supply.
Example
DECLARE REAL John_grade, &
Bob_grade, &
Joe_grade, &
highest_grade
INPUT "John's grade";John_grade
INPUT "Bob's grade";Bob_grade
INPUT "Joe's grade";Joe_grade
highest_grade = MAX(John_grade, Bob_grade, Joe_grade)
PRINT "The highest grade is";highest_grade
|
Output
John's grade? 90
Bob's grade? 95
Joe's grade? 79
The highest grade is 95
|
MID$
MID$ can be used either as a statement or as a function. The MID$
statement performs substring insertion into a string. The MID$ function
extracts a specified substring from a string expression.
Format
Syntax Rules
- Int-exp1 specifies the position of the substring's first
character.
- Int-exp2 specifies the length of the substring.
Remarks
- If int-exp1 is less than 1, BASIC assumes a
starting character position of 1.
- If int-exp2 is less than or equal to zero, BASIC
assumes a length of zero.
- If you specify a floating-point expression for int-exp1 or
int-exp2, BASIC truncates it to a LONG integer.
- MID$ statement
- The MID$ statement replaces a specified portion of str-var
with str-exp.
- If int-exp1 is greater than the length of
str-var, str-var remains unchanged.
- The length of str-var does not change regardless of the
value of int-exp2.
- If the optional int-exp2 is not specified, BASIC
assumes int-exp2 to be the length of str-exp
minimized by the length of str-var minus int-exp1.
For example:
A$ = "ABCDEFG"
MID$ (A$,3) = "123456789"
PRINT A$
|
Output
- If int-exp2 is less than or equal to zero,
str-var remains unchanged.
- If int-exp2 is greater than the length of
str-var, BASIC assumes int-exp2 to be equal
to the length of str-var.
- Int-exp2 is always minimized against the length of
str-var minus int-exp1.
- MID$ function
- The MID$ function extracts a substring from str-exp and
stores it in str-var.
- If int-exp1 is greater than the length of
str-exp, MID$ returns a null string.
- If int-exp2 is greater than the length of
str-exp, BASIC returns the string that begins at
int-exp1 and includes all characters remaining in
str-exp.
- If int-exp2 is less than or equal to zero, MID$ returns a
null string.
Examples
Example 1
!MID$ Function
DECLARE STRING old_string, new_string
old_string = "ABCD"
new_string = MID$(old_string,1,3)
PRINT new_string
|
Output
Example 2
!MID$ Statement
DECLARE STRING old_string, replace_string
old_string = "ABCD"
replace_string = "123"
PRINT old_string
MID$(old_string,1,3) = replace_string
PRINT old_string
|
Output
MIN
The MIN function compares the values of two or more numeric expressions
and returns the smallest value.
Format
Syntax Rules
BASIC allows you to specify up to eight numeric expressions.
Remarks
- If you specify values with different data types, BASIC
performs data type conversions to maintain precision.
- BASIC returns a function result whose data type is
compatible with the values you supply.
Example
DECLARE REAL John_grade, &
Bob_grade, &
Joe_grade, &
lowest_grade
INPUT "John's grade";John_grade
INPUT "Bob's grade";Bob_grade
INPUT "Joe's grade";Joe_grade
lowest_grade = MIN(John_grade, Bob_grade, Joe_grade)
PRINT "The lowest grade is";lowest_grade
|
Output
John's grade? 95
Bob's grade? 100
Joe's grade? 84
The lowest grade is 84
|
MOD
The MOD function divides a numeric value by another numeric value and
returns the remainder.
Format
Syntax Rules
Num-exp1 is divided by num-exp2.
Remarks
- If you specify values with different data types, BASIC
performs data type conversions to maintain precision.
- BASIC returns a function result whose data type is
compatible with the values you supply.
- The function result is either a positive or negative value,
depending on the value of the first numeric expression. For example, if
the first numeric expression is negative, then the function result will
also be negative.
Example
DECLARE REAL A,B
A = 500
B = MOD(A,70)
PRINT "The remainder equals";B
|
Output
MOVE
The MOVE statement transfers data between a record buffer and a list of
variables.
Format
Syntax Rules
- Chnl-exp is a numeric expression that specifies a channel
number associated with a file. It must be immediately preceded by a
number sign (#).
- Move-item specifies the variable or array to which or from
which data is to be moved.
- Parentheses indicate the number of dimensions in a numeric array.
The number of dimensions is equal to the number of commas plus 1. Empty
parentheses indicate a one-dimensional array, one comma indicates a
two-dimensional array, and so on.
- Str-var and str-array specify a fixed length
string variable or array. Parentheses indicate the number of dimensions
in a string array. The number of dimensions is equal to the number of
commas plus 1. You can specify the number of bytes to be reserved for
the variable or array elements with the =int-exp clause. The
default string length for a MOVE FROM statement is 16. For a MOVE TO
statement, the default is the string's length.
- The FILL, FILL%, and FILL$ keywords allow you to transfer fill
items of a specific data type. Table 4-1 shows FILL item formats,
representations, and storage requirements.
- If you specify a data type before the FILL keyword, the fill is of
that data type. If you do not specify a data type, the fill is of the
default data type. Data-type can be any BASIC data
type keyword or a data type defined by a RECORD statement. Data type
keywords, size, range, and precision are listed in Table 1-2.
- FILL items following a data type other than STRING cannot end with
a dollar sign. FILL items following a data type other than BYTE, WORD,
LONG, QUAD, or INTEGER cannot end with a percent sign.
- FILL% indicates integer fill. FILL$ indicates string fill. The
=int-exp clause specifies the number of bytes to be moved for
string FILL items.
- Int-exp specifies the number of FILL items to be moved. In
the applicable formats of FILL, (int-exp) represents a repeat
count, not an array subscript. FILL (n), for example,
represents n elements, not n + 1.
- You cannot use an expression or function reference as a
move-item.
Remarks
- Before a MOVE FROM statement can execute, the file associated with
chnl-exp must be open and there must be a record in the record
buffer.
- A MOVE statement neither transfers data to or from external
devices, nor invokes OpenVMS Record Management Services (RMS). Instead,
it transfers data between user areas. Thus, a record should first be
fetched with the GET statement before you use a MOVE FROM statement,
and a MOVE TO statement should be followed by a PUT or UPDATE statement
that writes the record to a file.
- MOVE FROM transfers data from the record buffer to the
move-item.
- MOVE TO transfers data from the move-item to the record
buffer.
- The MOVE statement does not affect the record buffer's size. If a
MOVE statement partially fills a buffer, the rest of the buffer is
unchanged. If there is more data in the variable list than in the
buffer, BASIC signals "MOVE overflows buffer"
(ERR=161).
- Each MOVE statement to or from a channel transfers data starting at
the beginning of the buffer. For example:
MOVE FROM #1%, I%, A$ = I%
|
In this example, BASIC assigns the first value in the
record buffer to I%; the value of I% is then used to
determine the length of A$.
- If a MOVE statement operates on an entire array, the following
conditions apply:
- BASIC transfers elements of row and column zero (in
contrast to the MAT statements).
- The storage size of the array elements and the size of the array
determine the amount of data moved. A MOVE statement that transfers
data from the buffer to a longword integer array transfers the first
four bytes of data into the first element (for example, (0,0)), the
next four bytes of data into element (0,1), and so on.
- If the MOVE TO statement specifies an explicit string length, the
following restrictions apply:
- If the string is equal to or longer than the explicit string
length, BASIC moves only the specified number of characters
into the buffer.
- If the string is shorter than the explicit string length,
BASIC moves the entire string and pads it with spaces to the
specified length.
- BASIC does not check the validity of data during the MOVE
operation.
Example
|