[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP BASIC for OpenVMS
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

MAT INPUT [ #chnl-exp , ] { array [ ( int-exp1 [, int-exp2 ] ) ] },...


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, HP 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 a lower bounds of zero.
  • If you do not specify bounds, HP BASIC creates the array and dimensions it to (10,10).
  • If you do specify upper bound, HP BASIC creates the array with the specified bounds. If the bounds exceed (10) or (10,10), HP 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, HP 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, HP 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, HP BASIC does not change the remaining array elements.
  • If there are more data elements in the input stream than there are array elements, HP BASIC ignores the excess.
  • Row zero and column zero are not changed.

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

MAT LINPUT [ #chnl-exp , ] { str-array [ ( int-exp1 [, int-exp2 ] ) ] },...


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, HP 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, HP BASIC creates the array and dimensions it to (10,10).
  • If you do specify upper bounds, HP BASIC creates the array with the specified bounds. If the bounds exceed (10) or (10,10), HP 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, HP 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, HP 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). HP 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 HP 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, HP 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, HP BASIC separates each array element with a space and starts each row on a new line.
    • If you do not use a separator character, HP 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. HP BASIC prints a blank line between arrays.
  • If the array does not exist, the following rules apply:
    • If you do not specify bounds, HP BASIC creates the array and dimensions it to (10,10).
    • If you specify upper bounds, HP BASIC creates the array with the specified bounds. If the bounds exceed (10) or (10,10), HP 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, HP 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), HP 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, HP 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

MAT READ { array [ ( int-exp1 [, int-exp2 ] ) ] },...


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, HP BASIC creates the array and dimensions it (10,10).
  • If you specify bounds, HP BASIC creates the array with the specified bounds. If the bounds exceed (10) or (10,10), HP 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, HP 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, HP 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

num-var = MAX ( num-exp1 , num-exp2 [ , num-exp3 ,... ] )


Syntax Rules

HP BASIC allows you to specify up to eight numeric expressions.


Remarks

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

MID$ statement
MID[$] ( str-var, int-exp1 [ , int-exp2 ] ) = str-exp

MID$ function
str-var = MID[$] (str-exp, int-exp1, int-exp2)


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, HP BASIC assumes a starting character position of 1.
  • If int-exp2 is less than or equal to zero, HP BASIC assumes a length of zero.
  • If you specify a floating-point expression for int-exp1 or int-exp2, HP 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, HP 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


      "AB12345"
      
    • 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, HP 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, HP 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


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

num-var = MIN ( num-exp1, num-exp2 [ , num-exp3 ,... ] )


Syntax Rules

HP BASIC allows you to specify up to eight numeric expressions.


Remarks

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

num-var = MOD ( num-exp1, num-exp2 )


Syntax Rules

Num-exp1 is divided by num-exp2.


Remarks

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


The remainder equals 10


Previous Next Contents Index