Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


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

  1. The RSET statement treats strings as fixed-length. It does not change the length of str-var, nor does it create new storage locations.
  2. If str-var is longer than str-exp, RSET right-justifies the data and pads it with spaces on the left.
  3. 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


X  123 


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

  1. Before you execute the SCRATCH statement, the file must be opened with ACCESS SCRATCH.
  2. The SCRATCH statement applies to ORGANIZATION SEQUENTIAL files only.
  3. The SCRATCH statement has no effect on terminals or unit record devices.
  4. 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.
  5. For magnetic tape files, the SCRATCH statement overwrites the current record with two end-of-file marks.
  6. Use of the SCRATCH statement on shared sequential files is not recommended.

Example


SCRATCH #4% 


SEG$

The SEG$ function extracts a substring from a main string, leaving the original string unchanged.

Format



Syntax Rules

None


Remarks

  1. 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.
  2. If int-exp1 is less than 1, BASIC assumes a value of 1.
  3. If int-exp1 is greater than int-exp2 or the length of str-exp, the SEG$ function returns a null string.
  4. If int-exp1 equals int-exp2, the SEG$ function returns the character at the position specified by int-exp1.
  5. 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.
  6. 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


DEFGH 


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

  1. Exp1 is the expression to be tested against the case-clauses and the else-clause. It can be numeric or string.
  2. Case-clause consists of the CASE keyword followed by a case-item and statements to be executed when the case-item is true.
  3. Else-clause consists of the CASE ELSE keywords followed by statements to be executed when no previous case-item has been selected as true.
  4. Case-item is either an expression to be compared with exp1 or a range of values separated with the keyword TO.

Remarks

  1. 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.
  2. Each statement in a SELECT block can have its own line number.
  3. 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.
  4. Each CASE keyword establishes a CASE block. The next CASE or END SELECT keyword ends the CASE block.
  5. You can nest SELECT blocks within a CASE or CASE ELSE block.
  6. 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.
  7. The following conditions constitute a match:
  8. 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.
  9. 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.
  10. 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

  1. If you do not specify a SET PROMPT statement, the default is SET PROMPT.
  2. 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.
  3. 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.
  4. 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

  1. If real-exp does not equal zero, SGN returns MAG(real-exp)/real-exp.
  2. If real-exp equals zero, SGN returns a value of zero.
  3. SGN returns an integer.

Example


DECLARE INTEGER sign 
sign = SGN(46/23) 
PRINT sign 

Output


 1 


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

  1. The returned value is from -1 to 1.
  2. 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


 1 


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

  1. Int-exp is the number of seconds BASIC waits before resuming program execution.
  2. 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

  1. Pressing the Return key on the controlling terminal cancels the effect of the SLEEP statement.
  2. 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


SLEEP 120% 


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

  1. BASIC treats an int-exp less than 0 as zero.
  2. 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


1234     5678 


SQR

The SQR function returns the square root of a positive number.

Format



Syntax Rules

None


Remarks

  1. BASIC signals the error "Imaginary square roots" (ERR=54) when real-exp is negative.
  2. 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


 10 


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

  1. The STATUS function returns a LONG integer.
  2. The value returned by the STATUS function is undefined until BASIC executes an OPEN statement.
  3. 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.
  4. 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


150      Y% = STATUS 


STOP

The STOP statement halts program execution allowing you to optionally continue execution.

Format



Syntax Rules

None


Remarks

  1. The STOP statement cannot appear before a PROGRAM, SUB, or FUNCTION statement.
  2. The STOP statement does not close files.
  3. 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.
  4. 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

  1. If num-exp is negative, the first character in the returned string is a minus sign (-).
  2. The STR$ function does not return leading or trailing spaces.
  3. 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.
  4. 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.
  5. 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


1543.66 


Previous Next Contents Index