Compaq BASIC for OpenVMS
Alpha and VAX
Systems
Reference Manual
RSET
The RSET statement assigns right-justified data to a string variable.
RSET does not change a string variable's length.
Format
Syntax Rules
Str-var cannot be a DEF function name unless the RSET
statement is inside the DEF function definition.
Remarks
- The RSET statement treats strings as fixed-length. It does not
change the length of str-var, nor does it create new storage
locations.
- If str-var is longer than str-exp, RSET
right-justifies the data and pads it with spaces on the left.
- If str-var is shorter than str-exp, RSET
truncates str-exp on the left.
Example
DECLARE STRING test
test = "ABCDE"
RSET test = "123"
PRINT "X" + test
|
Output
SCRATCH
The SCRATCH statement deletes the current record and all following
records in a sequential file.
Format
Syntax Rules
Chnl-exp is a numeric expression that specifies a channel
associated with a file. It must be immediately preceded by a number
sign (#).
Remarks
- Before you execute the SCRATCH statement, the file must be opened
with ACCESS SCRATCH.
- The SCRATCH statement applies to ORGANIZATION SEQUENTIAL files only.
- The SCRATCH statement has no effect on terminals or unit record
devices.
- For disk files, the SCRATCH statement discards the current record
and all that follows it in the file. The physical length of the file
does not change.
- For magnetic tape files, the SCRATCH statement overwrites the
current record with two end-of-file marks.
- Use of the SCRATCH statement on shared sequential files is not
recommended.
Example
SEG$
The SEG$ function extracts a substring from a main string, leaving the
original string unchanged.
Format
Syntax Rules
None
Remarks
- BASIC extracts the substring from str-exp, the
main string, and stores the substring in str-var. The
substring begins with the character in the position specified by
int-exp1 and ends with the character in the position specified
by int-exp2.
- If int-exp1 is less than 1, BASIC assumes a value
of 1.
- If int-exp1 is greater than int-exp2 or the
length of str-exp, the SEG$ function returns a null string.
- If int-exp1 equals int-exp2, the SEG$ function
returns the character at the position specified by int-exp1.
- Unless int-exp2 is greater than the length of
str-exp, the length of the returned substring equals
int-exp2 minus int-exp1 plus 1. If int-exp2
is greater than the length of str-exp, the SEG$ function
returns all characters from the position specified by int-exp1
to the end of str-exp.
- If you specify a floating-point expression for int-exp1 or
int-exp2, BASIC truncates it to a LONG integer.
Example
DECLARE STRING alpha, center
alpha = "ABCDEFGHIJK"
center = SEG$(alpha, 4, 8)
PRINT center
|
Output
SELECT
The SELECT statement lets you specify an expression, a number of
possible values the expression may have, and a number of alternative
statement blocks to be executed for each possible case.
Format
Syntax Rules
- Exp1 is the expression to be tested against the
case-clauses and the else-clause. It can be numeric
or string.
- Case-clause consists of the CASE keyword followed by a
case-item and statements to be executed when the
case-item is true.
- Else-clause consists of the CASE ELSE keywords followed by
statements to be executed when no previous case-item has been
selected as true.
- Case-item is either an expression to be compared with
exp1 or a range of values separated with the keyword TO.
- Rel-op is a relational operator specifying how
exp1 is to be compared to exp2. If you do not include
a rel-op, BASIC assumes the equals (=) operator.
BASIC executes the statements in the CASE block when the
specified relational expression is true.
- Exp3 and exp4 specify a range of numeric or
string values separated by the keyword TO. Multiple ranges must be
separated with commas. BASIC executes the statements in the
CASE block when exp1 falls within any of the specified ranges.
Remarks
- A SELECT statement can have only one else-clause. The
else-clause is optional and, when present, must be the last
CASE block in the SELECT block.
- Each statement in a SELECT block can have its own line number.
- The SELECT statement begins the SELECT block and the END SELECT
keywords terminate it. BASIC signals an error if you do not
include the END SELECT keywords.
- Each CASE keyword establishes a CASE block. The next CASE or END
SELECT keyword ends the CASE block.
- You can nest SELECT blocks within a CASE or CASE ELSE block.
- BASIC evaluates exp1 when the SELECT statement is
first encountered; BASIC then compares exp1 with each
case-clause in order of occurrence until a match is found or
until a CASE ELSE block or END SELECT is encountered.
- The following conditions constitute a match:
- Exp1 satisfies the relationship to exp2 specified
by rel-op.
- Exp1 is greater than or equal to exp3, but less
than or equal to exp4, greater than or equal to exp5
but less than or equal to exp6, and so on.
- When a match is found between exp1 and a
case-item, BASIC executes the statements in the CASE
block where the match occurred. If ranges overlap, the first match
causes BASIC to execute the statements in the CASE block.
After executing CASE block statements, control passes to the statement
immediately following the END SELECT keywords.
- If no CASE match occurs, BASIC executes the statements in
the else-clause, if present, and then passes control to the
statement immediately following the END SELECT keywords.
- If no CASE match occurs and you do not supply a case-else
clause, control passes to the statement following the END SELECT
keywords.
Example
100 SELECT A% + B% + C%
CASE = 100
PRINT 'THE VALUE IS EXACTLY 100'
CASE 1 TO 99
PRINT 'THE VALUE IS BETWEEN 1 AND 99'
CASE > 100
PRINT 'THE VALUE IS GREATER THAN 100'
CASE ELSE
PRINT 'THE VALUE IS LESS THAN 1'
END SELECT
|
SET PROMPT
The SET PROMPT statement enables a question mark prompt to appear after
BASIC executes either an INPUT, LINPUT, INPUT LINE, MAT INPUT,
or MAT LINPUT statement on channel #0. The SET NO PROMPT statement
disables the question mark prompt.
Format
Syntax Rules
None
Remarks
- If you do not specify a SET PROMPT statement, the default is SET
PROMPT.
- SET NO PROMPT disables BASIC from issuing a question mark
prompt for the INPUT, LINPUT, INPUT LINE, MAT INPUT, and MAT LINPUT
statements on channel #0.
- Prompting is reenabled when either a SET PROMPT statement or a
CHAIN statement is executed, or when a NEW, OLD, RUN or SCRATCH command
is executed in the VAX BASIC Environment.
- The SET NO PROMPT statement does not affect the string constant you
specify as the input prompt with the INPUT statement.
Example
DECLARE STRING your_name, your_age, your_grade
INPUT "Enter your name";your_name
SET NO PROMPT
INPUT "Enter your age"; your_age
SET PROMPT
INPUT "Enter the last school grade you completed";your_grade
|
Output
Enter your name? Katherine Kelly
Enter your age 15
Enter the last school grade you completed? 9
|
SGN
The SGN function determines whether a numeric expression is positive,
negative, or zero. It returns 1 if the expression is positive, -1 if
the expression is negative, and zero if the expression is zero.
Format
Syntax Rules
None
Remarks
- If real-exp does not equal zero, SGN returns
MAG(real-exp)/real-exp.
- If real-exp equals zero, SGN returns a value of zero.
- SGN returns an integer.
Example
DECLARE INTEGER sign
sign = SGN(46/23)
PRINT sign
|
Output
SIN
The SIN function returns the sine of an angle in radians or degrees.
Format
Syntax Rules
Real-exp is an angle specified in radians or degrees depending
upon which angle clause you choose with the OPTION statement.
Remarks
- The returned value is from -1 to 1.
- BASIC expects the argument of the SIN 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
OPTION ANGLE = RADIANS
DECLARE REAL s1_angle
s1_angle = SIN(PI/2)
PRINT s1_angle
|
Output
SLEEP
The SLEEP statement suspends program execution for a specified number
of seconds or until a carriage return is entered from the controlling
terminal.
Format
Syntax Rules
- Int-exp is the number of seconds BASIC waits
before resuming program execution.
- Int-exp must be from 0 to the largest allowed positive
integer value; if it is greater, BASIC signals the error
"Integer error or overflow" (ERR=51).
Remarks
- Pressing the Return key on the controlling terminal cancels the
effect of the SLEEP statement.
- All characters typed while SLEEP is in effect, including a Return
entered to terminate the SLEEP statement, remain in the typeahead
buffer. Therefore, if you type RETURN without preceding data, an INPUT
statement that follows SLEEP completes without data.
Example
SPACE$
The SPACE$ function creates a string containing a specified number of
spaces.
Format
Syntax Rules
Int-exp specifies the number of spaces in the returned string.
Remarks
- BASIC treats an int-exp less than 0 as zero.
- If you specify a floating-point expression for int-exp,
BASIC truncates it to an integer.
Example
DECLARE STRING A, B
A = "1234"
B = "5678"
PRINT A + SPACE$(5%) + B
|
Output
SQR
The SQR function returns the square root of a positive number.
Format
Syntax Rules
None
Remarks
- BASIC signals the error "Imaginary square roots"
(ERR=54) when real-exp is negative.
- BASIC assumes that the argument of the SQR function is 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 returns a value of the default
floating-point size.
Example
DECLARE REAL root
root = SQR(20*5)
PRINT root
|
Output
STATUS
The STATUS function returns an integer value containing information
about the last opened channel. Your program can test each bit to
determine the status of the channel.
Note
The STATUS function is supported only for compatibility with other
versions of BASIC. It is recommended that you use the RMSSTATUS
function for new program development.
|
Format
Syntax Rules
None
Remarks
- The STATUS function returns a LONG integer.
- The value returned by the STATUS function is undefined until
BASIC executes an OPEN statement.
- The STATUS value is reset by every input operation on any channel;
therefore, you should copy the STATUS value to a different storage
location before your program executes another input operation.
- If an error occurs during an input operation, the value of STATUS
is undefined. When no error occurs, the 6 low-order bits of the
returned value contain information about the type of device accessed by
the last input operation. Table 4-5 lists STATUS bits set by
BASIC.
Table 4-5 BASIC STATUS Bits
Bit Set |
Device Type |
0
|
Record-oriented device
|
1
|
Carriage-control device
|
2
|
Terminal
|
3
|
Directory device
|
4
|
Single directory device
|
5
|
Sequential block-oriented device (magnetic tape)
|
Example
STOP
The STOP statement halts program execution allowing you to optionally
continue execution.
Format
Syntax Rules
None
Remarks
- The STOP statement cannot appear before a PROGRAM, SUB, or FUNCTION
statement.
- The STOP statement does not close files.
- When a STOP statement executes in a program executed with the RUN
command in the VAX BASIC Environment, BASIC prints the line
number and module name associated with the STOP statement, then
displays the Ready prompt. In response to the prompt, you can type
immediate mode statements, CONTINUE to resume program execution, or any
valid compiler command. See the Compaq BASIC for OpenVMS Alpha and VAX Systems User Manual for more information
about immediate mode.
- When a STOP statement is in an executable image, the line number,
module name, and a number sign (#) prompt are printed. In response to
the prompt, you can type CONTINUE to continue program execution or EXIT
to end the program. If the program module was compiled with the /NOLINE
qualifier, no line number is displayed.
Example
PROGRAM Stopper
PRINT "Type CONTINUE when the program stops"
INPUT "Do you want to stop now"; Quit$
IF Quit$ = "Y"
THEN
STOP
ELSE
PRINT "So what are you waiting for?"
STOP
END IF
PRINT "You told me to continue... thank you"
END PROGRAM
|
Output
Type CONTINUE when the program stops
Do you want to stop now?n
So what are you waiting for?
Stop
In module STOPPER
Ready
continue
You told me to continue... thank you
Ready
|
STR$
The STR$ function changes a numeric expression to a numeric character
string without leading and trailing spaces.
Format
Syntax Rules
None
Remarks
- If num-exp is negative, the first character in the
returned string is a minus sign (-).
- The STR$ function does not return leading or trailing spaces.
- When you print a floating-point number that has 6 decimal digits or
more but the integer portion has 6 digits or less (for example,
1234.567), BASIC rounds the number to 6 digits (1234.57). If a
floating-point number's integer part is 7 decimal digits or more,
BASIC rounds the number to 6 digits and prints it in E format.
- When you print a floating-point number with magnitude from 0.1 to
1, BASIC rounds it to 6 digits. When you print a number with
magnitude smaller than 0.1, BASIC rounds it to 6 digits and
prints it in E format.
- The STR$ function returns up to 10 digits for LONG integers and up
to 31 digits for DECIMAL numbers.
Example
DECLARE STRING new_num
new_num = STR$(1543.659)
PRINT new_num
|
Output