[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP BASIC for OpenVMS
Reference Manual


Previous Contents Index


SCRATCH

The SCRATCH statement deletes the current record and all following records in a sequential file.

Format

SCRATCH #chnl-exp


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


SCRATCH #4%

SEG$

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

Format

str-var = SEG$ (str-exp, int-exp1, int-exp2)


Syntax Rules

None


Remarks

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

  • 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, HP BASIC assumes the equals (=) operator. HP 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. HP 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. HP 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.
  • HP BASIC evaluates exp1 when the SELECT statement is first encountered; HP 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, HP BASIC executes the statements in the CASE block where the match occurred. If ranges overlap, the first match causes HP 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, HP 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 HP 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

SET [NO] PROMPT


Syntax Rules

None


Remarks

  • If you do not specify a SET PROMPT statement, the default is SET PROMPT.
  • SET NO PROMPT disables HP 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.
  • 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

int-var = SGN (real-exp)


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


 1

SIN

The SIN function returns the sine of an angle in radians or degrees.

Format

real-var = SIN (real-exp)


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.
  • HP BASIC expects the argument of the SIN function to be a real expression. When the argument is a real expression, HP BASIC returns a value of the same floating-point size. When the argument is not a real expression, HP 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

SLEEP int-exp


Syntax Rules

  • Int-exp is the number of seconds HP BASIC waits before resuming program execution.
  • Int-exp must be from 0 to the largest allowed positive integer value; if it is greater, HP 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


SLEEP 120%

SPACE$

The SPACE$ function creates a string containing a specified number of spaces.

Format

str-var = SPACE$ (int-exp)


Syntax Rules

Int-exp specifies the number of spaces in the returned string.


Remarks

  • HP BASIC treats an int-exp less than 0 as zero.
  • If you specify a floating-point expression for int-exp, HP 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

  • HP BASIC signals the error "Imaginary square roots" (ERR=54) when real-exp is negative.
  • HP BASIC assumes that the argument of the SQR function is a real expression. When the argument is a real expression, HP BASIC returns a value of the same floating-point size. When the argument is not a real expression, HP 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

int-var = STATUS


Syntax Rules

None


Remarks

  • The STATUS function returns a LONG integer.
  • The value returned by the STATUS function is undefined until HP 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 3-5 lists STATUS bits set by HP BASIC.

Table 3-5 HP 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

STOP


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 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

str-var = STR$ (num-exp)


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), HP BASIC rounds the number to 6 digits (1234.57). If a floating-point number's integer part is 7 decimal digits or more, HP 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, HP BASIC rounds it to 6 digits. When you print a number with magnitude smaller than 0.1, HP 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


1543.66

STRING$

The STRING$ function creates a string containing a specified number of identical characters.

Format

str-var = STRING$ (int-exp1, int-exp2)


Syntax Rules

  • Int-exp1 specifies the character string's length.
  • Int-exp2 is the decimal ASCII value of the character that makes up the string. This value is treated modulo 256.

Remarks

  • HP BASIC signals the error "String too long" (ERR=227) if int-exp1 is greater than 65535.
  • If int-exp1 is less than or equal to zero, HP BASIC treats it as zero.
  • HP BASIC treats int-exp2 as an unsigned 8-bit integer. For example, --1 is treated as 255.
  • If either int-exp1 or int-exp2 is a floating-point expression, HP BASIC truncates it to an integer.

Example


DECLARE STRING output_str
output_str = STRING$(10%, 50%)  !50 is the ASCII value of the
PRINT output_str                !character "2"

Output


2222222222

SUB

The SUB statement marks the beginning of a HP BASIC subprogram and specifies the number and data type of its parameters.

Format



Syntax Rules

  • Sub-name is the name of the separately compiled subprogram.
  • Formal-param specifies the number and type of parameters for the arguments the SUB subprogram expects to receive when invoked.
    • Empty parentheses indicate that the SUB subprogram has no parameters.
    • Data-type specifies the data type of a parameter. If you do not specify a data type, parameters are of the default data type and size. When you do specify a data type, all following parameters are of that data type until you specify a new data type. Data type keywords and their size, range, and precision are listed in Table 1-2.
  • Sub-name can have from 1 to 31 characters and must conform to the following rules:
    • The first character of an unquoted name must be an alphabetic character (A to Z). The remaining characters, if present, can be any combination of letters, digits (0 to 9), dollar signs ($), periods (.), or underscores (_).
    • A quoted name can consist of any combination of printable ASCII characters.
  • Data-type can be any HP BASIC data type keyword or a data type defined by a RECORD statement.
  • Pass-mech specifies the parameter passing mechanism by which the subprogram receives arguments.
  • A pass-mech clause outside the parentheses applies by default to all SUB parameters. A pass-mech clause in the formal-param list overrides the specified default and applies only to the immediately preceding parameter.

Remarks

  • The SUB statement must be the first statement in the SUB subprogram.
  • Compiler directives and comment fields created with an exclamation point (!), can precede the SUB statement because they are not BASIC statements. Note that REM is a BASIC statement; therefore, it cannot precede the SUB statement.
  • Every SUB statement must have a corresponding END SUB statement or SUBEND statement.
  • If you do not specify a passing mechanism, the SUB program receives arguments by the default passing mechanisms.
  • Parameters defined in formal-param must agree in number, type, ordinality, and passing mechanism with the arguments specified in the CALL statement of the calling program.
  • You can specify up to 255 parameters.
  • Any HP BASIC statement except those that refer to other program unit types (FUNCTION, PICTURE or PROGRAM) can appear in a SUB subprogram.
  • All variables, except those named in MAP and COMMON statements are local to that subprogram.
  • HP BASIC initializes local variables to zero or the null string.
  • SUB subprograms receive parameters by reference, by descriptor, or by value.
    • BY REF specifies that the subprogram receives the argument's address.
    • BY DESC specifies that the subprogram receives the address of a BASIC descriptor. For information about the format of a BASIC descriptor for strings and arrays, see the HP BASIC for OpenVMS User Manual. For information about other types of descriptors, see the VAX Architecture Handbook.
    • BY VALUE specifies that the subprogram receives a copy of the argument value.
  • By default, HP BASIC subprograms receive numeric unsubscripted variables by reference, and all other parameters by descriptor. You can override these defaults for strings and arrays with a BY clause:
    • If you specify a string length with the =int-const clause, you must also specify BY REF. If you specify BY REF and do not specify a string length, HP BASIC uses the default string length of 16.
    • If you specify array bounds, you must also specify BY REF.
  • Subprograms can be called recursively.

Example


SUB SUB3 BY REF (DOUBLE A, B,      &
    STRING Emp_nam BY DESC,        &
    wage(20))
   .
   .
   .
END SUB


Previous Next Contents Index