Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index

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

  1. Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).
  2. 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.
  3. Int-exp1 and int-exp2 define the upper bounds of the array being implicitly created or the dimensions of an existing array.
  4. If you are creating an array, int-exp1 and int-exp2 cannot exceed 10.

Remarks

  1. You cannot use the MAT INPUT statement on arrays of more than two dimensions.
  2. You cannot use the MAT INPUT statement on arrays of data type DECIMAL or on arrays named in a RECORD statement.
  3. All arrays specified with the MAT INPUT statement must have lower bounds of zero.
  4. If you do not specify bounds, BASIC creates the array and dimensions it to (10,10).
  5. 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).
  6. To use the MAT INPUT statement with arrays larger than (10,10), create the input and output arrays with the DIM statement.
  7. When the array exists, the following rules apply:
  8. 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.
  9. 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.
  10. The MAT INPUT statement assigns values by row. For example, it assigns values to all elements in row 1 before beginning row 2.
  11. The MAT INPUT statement assigns the row number of the last data element transferred into the array to the system variable NUM.
  12. The MAT INPUT statement assigns the column number of the last data element transferred into the array to the system variable NUM2.
  13. If there are fewer elements in the input data than there are array elements, BASIC does not change the remaining array elements.
  14. If there are more data elements in the input stream than there are array elements, BASIC ignores the excess.
  15. Row zero and column zero are not changed.
  16. 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

  1. 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 (#).
  2. 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.
  3. Int-exp1 and int-exp2 define the upper bounds of the array being implicitly created or the dimensions of an existing array.
  4. If you are creating an array, int-exp1 and int-exp2 cannot exceed 10.

Remarks

  1. You cannot use the MAT LINPUT statement on arrays of more than two dimensions.
  2. You cannot use the MAT LINPUT statement on arrays of data type other than STRING or on arrays named in a RECORD statement.
  3. If you do not specify bounds, BASIC creates the array and dimensions it to (10,10).
  4. 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).
  5. All arrays specified with the MAT LINPUT statement must have lower bounds of zero.
  6. To use MAT LINPUT with arrays larger than (10,10), create the input arrays with the DIM statement.
  7. When the array exists, the following rules apply:
  8. 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.
  9. The MAT LINPUT statement assigns the row number of the last data element transferred into the array to the system variable NUM.
  10. The MAT LINPUT statement assigns the column number of the last data element transferred into the array to the system variable NUM2.
  11. Typing only a line terminator in response to the question mark prompt causes BASIC to assign a null string to that string array element.
  12. 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

  1. 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 (#).
  2. 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.
  3. Int-exp1 and int-exp2 define the upper bounds of the array being implicitly created or the dimensions of an existing array.
  4. The separator (comma or semicolon) determines the output format for the array.

Remarks

  1. You cannot use the MAT PRINT statement on arrays of more than two dimensions.
  2. You cannot use the MAT PRINT statement on arrays of data type DECIMAL or on arrays named in a RECORD statement.
  3. 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.
  4. If the array does not exist, the following rules apply:
  5. All arrays specified with the MAT PRINT statement must have lower bounds of zero.
  6. When the array exists, the following rules apply:
  7. The MAT PRINT statement does not print elements in row or column zero.
  8. 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

  1. Int-exp1 and int-exp2 define the upper bounds of the array being implicitly created or the dimensions of an existing array.
  2. If you are creating an array, int-exp1 and int-exp2 cannot exceed 10.

Remarks

  1. If you do not specify bounds, BASIC creates the array and dimensions it (10,10).
  2. 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).
  3. To read arrays larger than (10,10), create the array with the DIM statement.
  4. All arrays specified with the MAT statement must have lower bounds of zero.
  5. When the array exists, the following rules apply:
  6. All the DATA statements must be in the same program unit as the MAT READ statement.
  7. 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.
  8. The MAT READ statement does not read elements into row or column
    zero.
  9. The MAT READ statement assigns the row number of the last data element transferred into the array to the system variable, NUM.
  10. The MAT READ statement assigns the column number of the last data element transferred into the array to the system variable, NUM2.
  11. You cannot use the MAT READ statement on arrays of more than two dimensions.
  12. 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

  1. If you specify values with different data types, BASIC performs data type conversions to maintain precision.
  2. 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

  1. Int-exp1 specifies the position of the substring's first character.
  2. Int-exp2 specifies the length of the substring.

Remarks

  1. If int-exp1 is less than 1, BASIC assumes a starting character position of 1.
  2. If int-exp2 is less than or equal to zero, BASIC assumes a length of zero.
  3. If you specify a floating-point expression for int-exp1 or int-exp2, BASIC truncates it to a LONG integer.
  4. MID$ statement
  5. MID$ function


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


ABC 

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


ABCD 
123D 


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

  1. If you specify values with different data types, BASIC performs data type conversions to maintain precision.
  2. 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

  1. If you specify values with different data types, BASIC performs data type conversions to maintain precision.
  2. BASIC returns a function result whose data type is compatible with the values you supply.
  3. 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


The remainder equals 10 


MOVE

The MOVE statement transfers data between a record buffer and a list of variables.

Format



Syntax Rules

  1. Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).
  2. Move-item specifies the variable or array to which or from which data is to be moved.
  3. 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.
  4. 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.
  5. 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.
  6. You cannot use an expression or function reference as a move-item.

Remarks

  1. 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.
  2. 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.
  3. MOVE FROM transfers data from the record buffer to the move-item.
  4. MOVE TO transfers data from the move-item to the record buffer.
  5. 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).
  6. 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$.

  7. If a MOVE statement operates on an entire array, the following conditions apply:
  8. If the MOVE TO statement specifies an explicit string length, the following restrictions apply:
  9. BASIC does not check the validity of data during the MOVE operation.

Example


Previous Next Contents Index