Compaq BASIC for OpenVMS
Alpha and VAX
The QUO$ function returns a numeric string that is the quotient of two
numeric strings. The precision of the returned numeric string depends
on the value of an integer argument.
- Str-exp1 and str-exp2 specify the numeric strings
you want to divide. A numeric string can contain an optional minus sign
(-), ASCII digits, and an optional decimal point (.).
- Int-exp specifies the numeric precision of
str-exp. Table 4-4 shows examples of rounding and
truncation and the values of int-exp that produce them.
- The QUO$ function does not support E-format notation.
- If str-exp consists of more than 60 characters,
BASIC signals the error "Illegal number" (ERR=52).
- Str-exp is rounded or truncated, or both, according to the
value of int-exp.
- If int-exp is from -60 to 60, rounding and truncation
occur as follows:
- For positive integer expressions, rounding occurs to the right of
the decimal place. For example, if int-exp is 1, rounding
occurs one digit to the right of the decimal place (the number is
rounded to the nearest tenth). If int-exp is 2, rounding
occurs two digits to the right of the decimal place (the number is
rounded to the nearest hundredth), and so on.
- If int-exp is zero, BASIC rounds to the nearest
- For negative integer expressions, rounding occurs to the left of
the decimal point. If int-exp is -1, for example,
BASIC moves the decimal point one place to the left, then
rounds to units. If int-exp is -2, rounding occurs two places
to the left of the decimal point; BASIC moves the decimal
point two places to the left, then rounds to tens.
- If int-exp is from 9940 to 10,060, truncation occurs as
- If int-exp is 10,000, BASIC truncates the number
at the decimal point.
- If int-exp is greater than 10,000 (10,000 plus
n), BASIC truncates the numeric string n
places to the right of the decimal point. For example, if int-exp
is 10,001 (10,000 plus 1), BASIC truncates the number
starting one place to the right of the decimal point. If int-exp
is 10,002 (10,000 plus 2), BASIC truncates the number
starting two places to the right of the decimal point, and so on.
- If int-exp is less than 10,000 (10,000 minus n),
BASIC truncates the numeric string n places to the
left of the decimal point. For example, if int-exp is 9999
(10,000 minus 1), BASIC truncates the number starting one
place to the left of the decimal point. If int-exp is 9998
(10,000 minus 2), BASIC truncates starting two places to the
left of the decimal point, and so on.
- If int-exp is not from -60 to 60 or 9940 to 10,060,
BASIC returns a value of zero.
- If you specify a floating-point expression for int-exp,
BASIC truncates it to an integer of the default size.
DECLARE STRING num_str1, &
num_str1 = "458996.43"
num_str2 = "123222.444"
quotient = QUO$(num_str1, num_str2, 2)
The RAD$ function converts a specified integer in Radix-50 format to a
The RAD$ function is supported only for compatibility with
BASIC-PLUS-2. It is recommended that you do not use the RAD$ function
for new program development.
- The RAD$ function does not support E-format notation.
- The RAD$ function converts int-var to a 3-character string
in Radix-50 format and stores it in str-var. Radix-50 format
allows you to store three characters of data as a 2-byte integer.
- BASIC supports the RAD$ function, but not its complement,
the FSS$ function.
- If you specify a floating-point variable for int-var,
BASIC truncates it to an integer of the default size.
DECLARE STRING radix
radix = RAD$(999)
The RANDOMIZE statement gives the random number function, RND, a new
- Without the RANDOMIZE statement, successive runs of the same
program generate the same random number sequence.
- If you use the RANDOMIZE statement before invoking the RND
function, the starting point changes for each run. Therefore, a
different random number sequence appears each time.
DECLARE REAL random_num
FOR I = 1 TO 2
random_num = RND
The RCTRLC function disables Ctrl/C trapping.
- After BASIC executes the RCTRLC function, Ctrl/C typed at
the terminal returns you to DCL command level or to the VAX BASIC
- RCTRLC always returns a value of zero.
The RCTRLO function cancels the effect of Ctrl/O typed on a specified
Chnl-exp must refer to a terminal.
- If you type Ctrl/O to cancel terminal output, nothing is printed on
the specified terminal until your program executes the RCTRLO or until
you enter another Ctrl/O, at which time normal terminal output resumes.
- The RCTRLO function always returns a value of zero.
- RCTRLO has no effect if the specified channel is open to a device
that does not use the Ctrl/O convention.
PRINT "A" FOR I% = 1% TO 10%
Y% = RCTRLO(0%)
PRINT "Normal output is resumed"
Normal output is resumed
The READ statement assigns values from a DATA statement to variables.
Var cannot be a DEF function name, unless the READ statement
is inside the multiline DEF body.
- If your program has a READ statement without DATA statements,
BASIC signals a compile-time error.
- When BASIC initializes a program unit, it forms a data
sequence of all values in all DATA statements. An internal pointer
points to the first value in the sequence.
- When BASIC executes a READ statement, it sequentially
assigns values from the data sequence to variables in the READ
statement variable list. As BASIC assigns each value, it
advances the internal pointer to the next value.
- BASIC signals the error "Out of data" (ERR=57)
if there are fewer data elements than READ statements. Extra data
elements are ignored.
- The data type of the value must agree with the data type of the
variable to which it is assigned or BASIC signals "Data
format error" (ERR=50).
- If you read a string variable, and the DATA element is an unquoted
string, BASIC ignores leading and trailing spaces. If the DATA
element contains any commas, they must be inside quotation marks.
- BASIC evaluates subscript expressions in the variable list
after it assigns a value to the preceding variable, and before it
assigns a value to the subscripted variable. In the following example,
BASIC assigns the value of 10 to variable A, then
assigns the string, LESTER, to array element A$(A).
READ A, A$(A)
DATA 10, LESTER
The string, LESTER, is assigned to A$(10).
DECLARE STRING A,B,C
DATA "X", "Y", "Z"
PRINT A + B + C
The REAL function converts a numeric expression or numeric string to a
specified or default floating-point data type.
Exp can be either numeric or string. If a string, it can
contain the ASCII digits 0 to 9, uppercase E, a plus sign (+), a minus
sign (-), and a period (.).
- BASIC evaluates exp, then converts it to the
specified REAL size. If you do not specify a size, BASIC uses
the default REAL size.
- BASIC ignores leading and trailing spaces and tabs if
exp is a string.
- The REAL function returns a value of zero when a string argument
contains only spaces and tabs, or when the argument is null.
- Alpha BASIC does not support the HFLOAT floating-point data
type. VAX BASIC does not support the SFLOAT, TFLOAT, and XFLOAT
floating-point data types.
DECLARE STRING any_num
INPUT "Enter a number";any_num
PRINT REAL(any_num, DOUBLE)
Enter a number? 123095959
The RECORD statement lets you name and define data structures in a
BASIC program and provides the BASIC interface to
Oracle CDD/Repository. You can use the defined RECORD name anywhere a
BASIC data type keyword is valid if all data types are valid
in that context.
- Each line of text in a RECORD, GROUP, or VARIANT block can have an
optional line number.
- Data-type can be a BASIC data type keyword or a
previously defined RECORD name. Table 1-2 lists and describes
BASIC data type keywords.
- If the data type of a rec-item is STRING, the string is
fixed-length. You can supply an optional string length with the =
int-const clause. If you do not specify a string length, the
default is 16.
- When you create an array of components with GROUP or create an
array as a rec-item, BASIC allows you to specify both
lower and upper bounds. The upper bound is required; the lower bound is
- Int-const1 specifies the lower bounds of the array.
- Int-const2 specifies the upper bounds of the array and
when accompanied by int-const1, must be preceded by the
- Int-const1 must be less than or equal to
- If you do not specify int-const1, BASIC uses zero
as the default lower bound.
- The total size of a RECORD cannot exceed 65,535 bytes. Also, a
RECORD that is used as an array component is limited to 32,767 bytes.
- The declarations between the RECORD statement and the END RECORD
statement are called a RECORD block.
- Variables and arrays in a RECORD definition are also called RECORD
- There must be at least one rec-component in a RECORD block.
- The RECORD statement names and defines a data structure called a
RECORD template, but does not allocate any storage. When you use the
RECORD template as a data type in a statement such as DECLARE, MAP,
or COMMON, you declare a RECORD instance. This declaration of the
RECORD instance allocates storage for the RECORD. For example:
This statement declares a variable named emp_rec, which is
an instance of the user-defined data type EMPLOYEE.
- The rec-name qualifies the group-name and the
group-name qualifies the rec-item. You can access a
particular rec-item within a record by specifying
rec-name::group-name::rec-item. This specification is called a
fully qualified reference. The full qualification of a
rec-item is also called a component path name.
- Rec-item must conform to the rules for naming
- Whenever you access an elementary record component, that is, a
variable named in a RECORD definition, you do it in the context of the
instance; therefore, rec-item names need not be unique in your
program. For example, you can have a variable called
first_name in any number of different RECORD definitions.
However, you cannot use a BASIC reserved keyword as a
rec-item name and you cannot have two variables or arrays with
the same name at the same level in the RECORD or GROUP definition.
- The group-name is optional in a rec-item
specification unless there is more than one rec-item with the
same name or the group-name has subscripts. For example:
DECLARE EMPLOYEE Emp_rec
STRING Street, City, State, Zip
END RECORD Address
STRING First = 15
STRING Middle = 1
STRING Last = 15
END GROUP Emp_name
END RECORD Employee
You can access the rec-item "Last" by specifying
only "Emp_rec::Last" because only one rec-item is
named "Last"; however, if you try to reference
"Emp_rec::City", BASIC signals an error because
"City" is an ambiguous field. "City" is a component
of both "Work" and "Home"; to access it, either
"Emp_rec::Work::City" or "Emp_rec::Home::City" must
- The declarations between the GROUP keyword and the END GROUP
keyword are called a GROUP block. The GROUP keyword is valid only
within a RECORD block.
- A subscripted group is similar to an array within the record. The
group can have both lower and upper bounds for one or more dimensions.
Each group element consists of all the record items contained within
the subscripted group including other groups.
- The declarations between the VARIANT keyword and the END VARIANT
keywords are called a VARIANT block.
- The amount of space allocated for a VARIANT field in a RECORD is
equal to the space needed for the variant field requiring the most
- A variant defines the record items that overlay other items,
allowing you to redefine the same storage one or more ways.
- Each case in a variant starts at the position in the record where
the variant begins.
- The size of a variant is the size of the longest case in that
1000 RECORD Employee
STRING Last = 15
STRING First = 14
STRING Middle = 1
END GROUP Emp_name
STRING Street = 15
STRING City = 20
STRING State = 2
END GROUP Emp_address
STRING Wage_class = 2
END GROUP Hourly
END GROUP Salaried
END GROUP Executive
END RECORD Employee
The RECOUNT function returns the number of characters transferred by
the last input operation.
- The RECOUNT value is reset by every input operation on any channel,
including channel #0.
- After an input operation from your terminal, RECOUNT contains the
number of characters (bytes), including line terminators, transferred.
- After accessing a file record, RECOUNT contains the number of
characters in the record.
- Because RECOUNT is reset by every input operation on any channel,
you should copy the RECOUNT value to a different storage location
before executing another input operation.
- If an error occurs during an input operation, the value of RECOUNT
- RECOUNT is unreliable after a Ctrl/C interrupt because the Ctrl/C
trap may have occurred before BASIC set the value for RECOUNT.
- The RECOUNT function returns a LONG value.
DECLARE INTEGER character_count
INPUT "Enter a sequence of numeric characters";character_count
character_count = RECOUNT
PRINT character_count;"characters received (including CR and LF)"
Enter a sequence of numeric characters? 12345678
10 characters received (including CR and LF)
The REM statement allows you to document your program.
- REM must be the only statement on the line or the last statement on
a multistatement line.
- BASIC interprets every character between the keyword REM
and the next line number as part of the comment.
- BASIC does not allow you to specify the REM statement in
programs that do not contain line numbers.
- Because the REM statement is not executable, you can place it
anywhere in a program, except where other statements, such as SUB and
END SUB, must be the first or last statement in a program unit.
- When the REM statement is the first statement on a line-numbered
line, BASIC treats any reference to that line number as a
reference to the next higher-numbered executable statement.
- The REM statement is similar to the comment field that begins with
an exclamation point, with one exception: the REM statement must be the
last statement on a BASIC line. The exclamation point comment field can
be ended with another exclamation point or a line terminator and
followed by a BASIC statement. See Chapter 1 for more
information about the comment field.
10 REM This is a multiline comment
All text up to BASIC line 20
is part of this REM statement.
Any BASIC statements on line 10
are ignored. PRINT "This does not
20 PRINT "This will execute"