Compaq BASIC for OpenVMS
Alpha and VAX
Systems
Reference Manual
COMP%
The COMP% function compares two numeric strings and returns -1, 0, or
1, depending on the results of the comparison.
Format
Syntax Rules
Str-exp1 and str-exp2 are numeric strings with an
optional minus sign (-), ASCII digits, and an optional decimal point
(.).
Remarks
- If str-exp1 is greater than str-exp2, COMP%
returns 1.
- If the string expressions are equal, COMP% returns 0.
- If str-exp1 is less than str-exp2, COMP% returns
-1.
- The value returned by the COMP% function is an integer of the
default size.
- The COMP% function does not support E-format notation.
Example
DECLARE STRING num_string, old_num_string, &
INTEGER result
num_string = "-24.5"
old_num_string = "33"
result = COMP%(num_string, old_num_string)
PRINT "The value is ";result
|
Output
CONTINUE
The CONTINUE statement causes BASIC to clear an error condition
and resume execution at the statement following the statement that
caused the error or at the specified target.
Format
Syntax Rules
If you specify a target, it must be a label or line number that appears
either inside the associated protected region, inside a WHEN block
protected region that surrounds the current protected region, or in an
unprotected region of code.
Remarks
- CONTINUE with no target causes BASIC to transfer control to
the statement immediately following the statement that caused the
error. The next remark is an exception to this rule.
- If an error occurs on a FOR, NEXT, WHILE, UNTIL, SELECT or CASE
statement, control is transferred to the statement immediately
following the corresponding NEXT or END SELECT statement, as in the
following code:
10 WHEN ERROR IN
A=10
B=1
20 FOR I=A TO B STEP 2
30 GET #1
40 C=1
NEXT I
50 C=0
USE
.
.
.
CONTINUE
END WHEN
|
If an error occurs on line 20, the CONTINUE statement transfers
control to line 50. If an error occurs on line 30, program control
resumes at line 40.
- The CONTINUE statement must be lexically inside of a handler.
- If you specify a CONTINUE statement within a detached handler, you
cannot specify a target.
Example
WHEN ERROR USE err_handler
.
.
.
END WHEN
.
.
.
HANDLER err_handler
SELECT ERR
CASE = 50
PRINT "Insufficient data"
CONTINUE
CASE ELSE
EXIT HANDLER
END SELECT
END HANDLER
|
COS
The COS function returns the cosine of an angle in radians or degrees.
Format
Syntax Rules
None
Remarks
- The returned value is from -1 to 1. The parameter value is
expressed in either radians or degrees depending on which angle clause
you choose with the OPTION statement.
- BASIC expects the argument of the COS function to be a real
expression. When the argument is a real expression, BASIC
returns a value of the same floating-point size. When the argument is
not a real expression, BASIC converts the argument to the
default floating-point size and returns a value of the default
floating-point size.
Example
DECLARE SINGLE cos_value
cos_value = 26
PRINT COS(cos_value)
|
Output
CTRLC
The CTRLC function enables Ctrl/C trapping. When Ctrl/C trapping is
enabled, a Ctrl/C typed at the terminal causes control to be
transferred to the error handler currently in effect.
Format
Syntax Rules
None
Remarks
- When BASIC encounters a Ctrl/C, control passes to the error
handler currently in effect. If there is no error handler in a program,
the program aborts.
- In a series of linked subprograms, setting Ctrl/C for one
subprogram enables Ctrl/C trapping for all subprograms.
- When you trap a Ctrl/C with an error handler, your program may be
in an inconsistent state; therefore, you should handle the Ctrl/C error
and exit the program as quickly as possible.
- Ctrl/C trapping is asynchronous; that is, BASIC suspends
execution and signals "Programmable ^C trap" (ERR=28) as soon
as it detects a Ctrl/C. Consequently, a statement can be interrupted
while it is executing. A statement so interrupted may be only partially
executed and variables may be left in an undefined state.
- BASIC can trap more than one Ctrl/C error in a program as
long as the error does not occur while the error handler is executing.
If a second Ctrl/C is detected while the error handler is processing
the first Ctrl/C, the program aborts.
- The CTRLC function always returns a value of zero.
- The function RCTRLC disables Ctrl/C trapping. See the description
of the RCTRLC function for further details.
Example
WHEN ERROR USE repair_work
Y% = CTRLC
.
.
.
END WHEN
HANDLER repair_work
IF (ERR=28) THEN PRINT "Interrupted by CTRLC!"
.
.
.
END HANDLER
|
CVT$$
The CVT$$ function is a synonym for the EDIT$ function. See the EDIT$
function for more information.
Note
It is recommended that you use the EDIT$ function rather than the CVT$$
function for new program development.
|
Format
CVTxx
The CVT$% function maps the first two characters of a string into a
16-bit integer. The CVT%$ function translates a 16-bit integer into a
2-character string. The CVT$F function maps a 4- or 8-character string
into a floating-point variable. The CVTF$ function translates a
floating-point number into a 4- or 8-byte character string. The number
of characters translated depends on whether the floating-point variable
is single- or double-precision.
Note
CVT functions are supported only for compatibility with BASIC-PLUS. It
is recommended that you use the BASIC dynamic mapping feature
or multiple MAP statements for new program development.
|
Format
Syntax Rules
CVT functions reverse the order of the bytes when moving them to or
from a string. Therefore, you can mix MAP and MOVE statements, but you
cannot use FIELD and CVT functions on a file if you also plan to use
MAP or MOVE statements.
Remarks
- CVT$%
- If the CVT$% str-var has fewer than two characters,
BASIC pads the string with nulls.
- If the default data type is LONG, only 2 bytes of data are
extracted from str-var; the high-order byte is sign-extended
into a longword.
- The value returned by the CVT$% function is an integer of the
default size.
- CVT%$
- Only 2 bytes of data are inserted into str-var.
- If you specify a floating-point variable for int-var,
BASIC truncates it to an integer of the default size. If the
default size is BYTE and the value of int-var exceeds 127,
BASIC signals an error.
- CVT$F
- CVT$F maps four characters when the program is compiled with
/SINGLE and eight characters when the program is compiled with /DOUBLE.
- If str-var has fewer than four or eight characters,
BASIC pads the string with nulls.
- The real-var returned by the CVT$F function is the default
floating-point size. If the default size is not SINGLE or DOUBLE,
BASIC signals the error "Floating CVT valid only for
SINGLE or DOUBLE."
- CVTF$
- The CVTF$ function maps single-precision numbers to a 4-character
string and double-precision numbers to an 8-character string.
- BASIC expects the argument of the CVTF$ function to be a
real expression. When the argument is a real expression, BASIC
returns a value of the same floating-point size. When the argument is
not a real expression, BASIC converts the argument to the
default floating-point size and returns a value of the default
floating-point size. If the default floating-point size is not SINGLE
or DOUBLE, BASIC signals the error "Floating CVT valid
only for SINGLE or DOUBLE."
Examples
Example 1
DECLARE STRING test_string, another_string
DECLARE LONG first_number, next_number
test_string = "AT"
PRINT CVT$%(test_string)
another_string = "at"
PRINT CVT$%(another_string)
first_number = 16724
PRINT CVT%$(first_number)
next_number = 24948
PRINT CVT%$(next_number)
END
|
Output
Example 2
DECLARE STRING test_string, another_string
DECLARE SINGLE first_num, second_num
test_string = "DESK"
first_num = CVT$F(test_string)
PRINT first_num
another_string = "desk"
second_num = CVT$F(another_string)
PRINT second_num
PRINT CVTF$(first_num)
PRINT CVTF$(second_num)
END
|
$ BASIC/SINGLE CVTF
$ LINK CVTF
$ RUN CVTF
|
Output
.218256E+12
.466242E+31
DESK
desk
|
DATA
The DATA statement creates a data block for the READ statement.
Format
Syntax Rules
- Num-lit specifies a numeric literal.
- Str-lit is a character string that starts and ends with
double or single quotation marks. The quotation marks must match.
- Unq-str is a character sequence that does not start or end
with double quotation marks and does not contain a comma.
- Commas separate data elements. If a comma is part of a data item,
the entire item must be enclosed in quotation marks.
Remarks
- Because BASIC treats comment fields in DATA statements as
part of the DATA sequence, you should not include comments.
- A DATA statement must be the last or the only statement on a
physical line.
- DATA statements must end with a line terminator.
- When a DATA statement is continued with an ampersand (&),
BASIC interprets all characters between the keyword DATA and
the ampersand as part of the data. Any code that appears on a
noncontinued line is considered a new statement.
- You cannot use the percent sign suffix for integer constants that
appear in DATA statements. An attempt to do so causes BASIC to
signal the error, "Data format error" (ERR=50).
- DATA statements are local to a program module.
- BASIC does not execute DATA statements. Instead, control is
passed to the next executable statement.
- A program can have more than one DATA statement. BASIC
assembles data from all DATA statements in a single program unit into a
lexically ordered single data block.
- BASIC ignores leading and trailing blanks and tabs unless
they are in a string literal.
- Commas are the only valid data delimiters. You must use a quoted
string literal if a comma is to be part of a string.
- BASIC ignores DATA statements without an accompanying READ
statement.
- BASIC signals the error "Data format error" if
the DATA item does not match the data type of the variable specified in
the READ statement or if a data element that is to be read into an
integer variable ends with a percent sign (%). If a string data element
ends with a dollar sign ($), BASIC treats the dollar sign as
part of the string.
Example
10 DECLARE INTEGER A,B,C
READ A,B,C
DATA 1,2,3
PRINT A + B + C
|
Output
DATE$
The DATE$ function returns a string containing a day, month, and year
in the form dd-mmm-yy.
Format
Syntax Rules
- Int-exp can have up to 6 digits in the form
yyyddd, where the characters yyy specify the number
of years since 1970 and the characters ddd specify the day of
that year. The day of year must be a value between 1 and the number of
days in the specified year.
- You must fill all three of the d positions with digits or
zeros before you can fill the y positions. For example:
- DATE$(121) returns the date 01--May--70, day 121 of the year 1970.
- DATE$(1201) returns the date 20--Jul--71, day 201 of the year 1971.
- DATE$(12001) returns the date 01--Jan--82, day one of the year 1982.
- DATE$(10202) returns the date 20--Jul--80, day 202 of the year 1980.
Remarks
- If int-exp equals zero, DATE$ returns the current date.
- The str-var returned by the DATE$ function consists of
nine characters and expresses the day, month, and year in the form
dd-mmm-yy.
- If you specify an invalid date, such as day 385, results are
unpredictable.
- If you specify a floating-point expression for int-exp,
BASIC truncates it to an integer of the default size.
Example
DECLARE STRING todays_date
todays_date = DATE$(0)
PRINT todays_date
|
Output
The DATE4$ function is strongly recommended as replacement for the
DATE$ function to avoid problems in the year 2000 and beyond. It
functions the same as the DATE$ function except that the year portion
of the result string contains two more digits indicating the century.
For example:
PRINT 32150, DATE$ (32150), DATE4$ (32150)
|
This produces the following output:
32150 30-May-02 30-May-2002
|
DATE4$
The DATE4$ function returns a string containing a day, month, and year
in the form dd-mmm-yyyy.
Format
Syntax Rules
- Int-exp can have up to 6 digits in the form
yyyddd, where the characters yyy specify the number
of years since 1970 and the characters ddd specify the day of
that year. The day of year must be a value between 1 and the number of
days in the specified year.
- You must fill all three of the d positions with digits or
zeros before you can fill the y positions.
Remarks
The DATE4$ function is strongly recommended as replacement for the
DATE$ function to avoid problems in the year 2000 and beyond. It
functions the same as the DATE$ function except that the year portion
of the result string contains two more digits indicating the century.
For example:
PRINT 32150, DATE$ (32150), DATE4$ (32150)
|
Produces the following output:
32150 30-May-02 30-May-2002
|
See the description of the DATE$ function for more information.
DECIMAL
The DECIMAL function converts a numeric expression or numeric string to
the DECIMAL data type.
Format
Syntax Rules
- Int-const1 specifies the total number of digits (the
precision) and int-const2 specifies the number of digits to
the right of the decimal point (the scale). If you do not specify these
values, BASIC uses the d (digits) and s (scale) defaults for
the DECIMAL data type.
- Int-const1 and int-const2 must be positive
integers from 1 to 31. Int-const2 cannot exceed the value of
int-const1.
- Exp can be either numeric or numeric string. If a numeric
string, it can contain the ASCII digits 0 to 9, a plus sign (+), a
minus sign (-), and a period (.).
Remarks
- If exp is a string, BASIC ignores leading and
trailing spaces and tabs.
- The DECIMAL function returns a zero when a string argument contains
only spaces and tabs, or when it is null.
Example
DECLARE STRING CONSTANT format_string = "##.###"
DECLARE STRING num_value, DECIMAL(5,3) B
INPUT "Enter a numeric value";num_value
B = DECIMAL(num_value,5,3)
PRINT USING format_string, B
|
Output
Enter a numeric value? 6
6.000
|
DECLARE
The DECLARE statement explicitly assigns a name and a data type to a
variable, an entire array, a function, or a constant.
Format
Syntax Rules
- 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.
- Variables
- Decl-item names an array, a record, or a variable.
- A decl-item named in a DECLARE statement cannot be named
in another DECLARE statement, or in a DEF, EXTERNAL, FUNCTION, SUB,
COMMON, MAP, DIM, HANDLER, or PICTURE statement.
- Each decl-item is associated with the preceding data type.
A data type is required for the first decl-item.
- Decl-items of data type STRING are dynamic strings.
- When you declare an array, BASIC allows you to specify both
lower and upper bounds for each dimension of the array. The upper bound
is required; the lower bound is optional.
- 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
keyword TO.
- Int-const1 must be less than or equal to
int-const2.
- If you do not specify int-const1, BASIC uses zero
as the default lower bound.
- Int-const1 and int-const2 can be any combination
of negative or positive values or zero.
- DEF Functions
- Def-name names the DEF function.
- Data-type specifies the data type of the value the
function returns.
- Def-params specify the number and, optionally, the data
type of the DEF parameters. Parameters define the arguments the DEF
expects to receive when invoked.
- When you specify a data type, all following parameters are of that
data type until you specify a new data type.
- If you do not specify any data type, parameters take the current
default data type and size.
- The number of parameters equals the number of commas plus 1. For
example, empty parentheses specify one parameter of the default type
and size; one comma inside the parentheses specifies two parameters of
the default type and size; and so on. One data type inside the
parentheses specifies one parameter of the specified data type; two
data types separated by one comma specifies two parameters of the
specified type, and so on.
- Named Constants
- Const-name is the name you assign to the constant.
- Data-type specifies the data type of the constant. The
value of the const must be numeric if the data type is numeric
and string if the data type is STRING. If the data type is STRING,
const must be a quoted string or another string constant.
- Const-exp cannot be a data type that was defined with the
RECORD statement.
- Data-type cannot be a data type defined by a record
statment.
- String constants cannot exceed 498 characters.
- BASIC allows const-exp to be an expression for all
data types except DECIMAL. Expressions are not allowed as values when
you name DECIMAL constants.
- Allowable operators in DECLARE CONSTANT expressions include all
valid arithmetic, relational, and logical operators except
exponentiation. Built-in functions cannot be used in DECLARE CONSTANT
expressions. The following examples use valid expressions as values:
DECLARE DOUBLE CONSTANT max_value = (PI/2)
DECLARE STRING CONSTANT left_arrow = "<-----" + LF + CR
|
Remarks
- The DECLARE statement is not executable.
- The DECLARE statement must lexically precede any reference to the
variables, functions, or constants named in it.
- To declare a virtual or run-time array, use the DIMENSION statement.
- Variables
- Subsequent decl-items are associated with the specified
data type until you specify another data type.
- All variables named in a DECLARE statement are initialized to zero
if numeric or to the null string if string.
- DEF Functions
- The DECLARE FUNCTION statement allows you to name a function
defined in a DEF or DEF* statement, specify the data type of the value
the function returns, and declare the number and data type of the
parameters.
- Data type keywords must be separated by commas.
- The first specification of a data type for a def-param is
the default for subsequent arguments until you specify another
def-param. For example:
DECLARE DOUBLE FUNCTION interest(DOUBLE,SINGLE,,)
|
This example declares two parameters of the default type and size,
one DOUBLE parameter, and three SINGLE parameters for the function
named interest.
- Named Constants
- The DECLARE CONSTANT statement allows you to name a constant value
and assign a data type to that value. Note that you can specify only
one data type in a DECLARE CONSTANT statement. To declare a constant of
another data type, you must use a second DECLARE CONSTANT statement.
- During program execution, you cannot change the value assigned to
the constant.
- The specified data-type determines the data type of the
constant. For example:
DECLARE LONG CONSTANT True = -1, False = 0
DECLARE REAL CONSTANT ZZZ = 123.0
DECLARE BYTE CONSTANT YYY = '123'L
PRINT True, False, ZZZ, YYY
|
Output