Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


EXIT

The EXIT statement lets you exit from a main program, a SUB, FUNCTION, or PICTURE subprogram, a multiline DEF, a statement block, or a handler.

Format



Syntax Rules

  1. The DEF, FUNCTION, SUB, HANDLER, and PROGRAM keywords specify the type of subprogram, multiline DEF, or handler from which BASIC is to exit.
  2. If you specify an optional expression with the EXIT DEF statement or with the EXIT FUNCTION statement, the expression becomes the function result and supersedes any function assignment. It also overrides any expression specified on the END DEF or END FUNCTION statement. Note that the expression must be compatible with the FUNCTION or DEF data type.
  3. Label specifies a statement label for an IF, SELECT, FOR, WHILE, or UNTIL statement block.

Remarks

  1. An EXIT SUB, EXIT FUNCTION, EXIT PROGRAM, EXIT DEF, or EXIT PICTURE statement is equivalent to an unconditional branch to an equivalent END statement. Control then passes to the statement that invoked the DEF or to the statement following the statement that called the subprogram.
  2. The EXIT HANDLER statement causes BASIC to transfer control to a specified area.
  3. The EXIT PROGRAM statement causes BASIC to exit from a main program module.
  4. The EXIT label statement is equivalent to an unconditional branch to the first statement following the end of the IF, SELECT, FOR, WHILE, or UNTIL statement labeled by the specified label.
  5. An EXIT FUNCTION, EXIT SUB or EXIT PROGRAM statement cannot be used within a multiline DEF function.
  6. When the EXIT FUNCTION, EXIT SUB or EXIT PROGRAM statement executes, BASIC releases all storage allocated to local variables and returns control to the calling program.


Example


DEF emp.bonus(A) 
IF A > 10 
THEN 
    PRINT "OUT OF RANGE" 
    EXIT DEF 0 
ELSE 
    emp.bonus = A * 4 
END IF 
END DEF 
INPUT A 
PRINT emp.bonus(A) 
END 

Output


? 11 
OUT OF RANGE 
 0 


EXP

The EXP function returns the value of the mathematical constant e raised to a specified power.

Format



Syntax Rules

None


Remarks

  1. The EXP function returns the value of e raised to the power of real-exp.
  2. BASIC expects the argument of the EXP 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.
  3. When the default REAL size is SINGLE, DOUBLE, or SFLOAT, EXP allows arguments from -88 to 88. If the default REAL size is GFLOAT or TFLOAT, EXP allows arguments from -709 to 709. If the default REAL size is HFLOAT or XFLOAT, the arguments can be in the range -11356 to 11355. When the argument exceeds the upper limit of a range, BASIC signals an error. When the argument is beyond the lower limit of a range, the EXP function returns a zero and BASIC does not signal an error.

Example


DECLARE SINGLE num_val 
num_val = EXP(4.6) 
PRINT num_val 

Output


 99.4843 


EXTERNAL

The EXTERNAL statement declares constants, variables, functions, and subroutines external to your program. You can describe parameters for external functions and subroutines.

Format



Syntax Rules

  1. For external constants, data-type can be BYTE, WORD, LONG, INTEGER (if default is not QUAD), SINGLE, SFLOAT, or REAL (if default is SINGLE or SFLOAT).
  2. For external variables, the data type can be any valid numeric data type.
  3. For external functions and subroutines, the data type can be BYTE, WORD, LONG, QUAD, SINGLE, DOUBLE, GFLOAT, HFLOAT, SFLOAT, TFLOAT, XFLOAT, DECIMAL, STRING, INTEGER, REAL, RFA, or a data type defined with the RECORD statement. See Table 1-2 for more information about data type size, range, and precision.
  4. The name of an external constant, variable, function, or subroutine can be from 1 to 31 characters.
  5. For all external routine declarations, the name must be a valid BASIC identifier and must not be the same as any other SUB, FUNCTION, PICTURE, or PROGRAM name.
    For more information about external pictures, see Programming with VAX BASIC Graphics.
  6. Param-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.
  7. Param-list is identical to external-param except that no OPTIONAL parameter is allowed.
  8. Parameters in the param-list must agree in number and data type with the parameters in the invocation. Param-data-type includes ANY, BYTE, WORD, LONG, QUAD, INTEGER, SINGLE, DOUBLE, GFLOAT, HFLOAT, SFLOAT, TFLOAT, XFLOAT, READ, a user-defined RECORD type, STRING, or RFA.
  9. A maximum of 255 parameters may be passed.
  10. External Functions and Subroutines
  11. Using ANY as a BASIC Data Type
  12. Passing Optional Parameters
  13. Declaring Array Dimensions
    The DIM keyword indicates that the parameter is an array. Commas specify array dimensions. The number of dimensions is equal to the number of commas plus 1. For example:


    EXTERNAL STRING FUNCTION new (DOUBLE, STRING DIM(,), DIM( )) 
    

    This statement declares a function named new that has three parameters. The first is a double-precision floating-point value, the second is a two-dimensional string array, and the third is a one-dimensional string array. The function returns a string result.


Remarks

  1. The EXTERNAL statement must precede any program reference to the constant, variable, function, subroutine or picture declared in the statement.
  2. The EXTERNAL statement is not executable.
  3. A name declared in an EXTERNAL CONSTANT statement can be used in any nondeclarative statement as if it were a constant.
  4. A name declared in an EXTERNAL FUNCTION statement can be used as a function invocation in an expression. In addition, you can invoke a function with the CALL statement unless the function data type is DECIMAL, HFLOAT, or STRING.
  5. A name declared in an EXTERNAL SUB statement can be used in a CALL statement.
  6. The optional pass-mech clauses in the EXTERNAL FUNCTION and EXTERNAL SUB statements tell BASIC how to pass arguments to a non BASIC function or subprogram.
  7. If you do not specify the data type ANY or declare parameters as optional, the arguments passed to external functions and subroutines should match the external parameters declared in the EXTERNAL FUNCTION or EXTERNAL SUB statement in number, type, and passing mechanism. BASIC forces arguments to be compatible with declared parameters. If they are not compatible, BASIC signals an error.

Examples

Example 1


!External Constant 
EXTERNAL LONG CONSTANT SS$_NORMAL 

Example 2


!External Variable 
EXTERNAL WORD SYSNUM 

Example 3


!External Function 
EXTERNAL DOUBLE FUNCTION USR$2(WORD,LONG,ANY) 

Example 4


!External Subroutine 
EXTERNAL SUB calc BY DESC (STRING DIM(,),  BYTE BY REF) 


FIELD

The FIELD statement dynamically associates string variables with all or parts of a record buffer. FIELD statements do not move data. Instead, they permit direct access through string variables to sections of a specified record buffer.

Note

The FIELD statement is supported only for compatibility with BASIC-PLUS-2. Because data defined in the FIELD statement can be accessed only as string data, you must use the CVTxx functions to process numeric data; therefore, you must convert string data to numeric after you move it from the record buffer. Then, after processing, you must convert numeric data back to string data before transferring it to the record buffer. It is recommended that you use the BASIC dynamic mapping feature or multiple maps instead of the FIELD statement and CVTxx functions.

Format



Syntax Rules

  1. Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#). A file must be open on the specified channel or BASIC signals an error.
  2. Int-exp specifies the number of characters in str-var. However, a subsequent int-exp cannot depend on the return string from a previous int-exp. For example, the following statement is illegal because the second int-exp depends on the return string A$:


    FIELD #1%, 1% AS A$, ASCII(A$) AS B$ 
    


Remarks

  1. A FIELD statement is executable. You can change a buffer description at any time by executing another FIELD statement. For example:


    FIELD #1%, 40% AS whole_field$ 
    FIELD #1%, 10% AS A$, 10% AS B$, 10% AS C$, 10% AS D$ 
    

    The first FIELD statement associates the first 40 characters of a buffer with the variable whole_field$. The second FIELD statement associates the first 10 characters of the same buffer with A$, the second 10 characters with B$, and so on. Later program statements can refer to any of the variables named in the FIELD statements to access specific portions of the buffer.

  2. You cannot define virtual array strings as string variables in a FIELD statement.
  3. A variable named in a FIELD statement cannot be used in a COMMON or MAP statement, as a parameter in a CALL or SUB statement, or in a MOVE statement.
  4. Attempting to access an element of a virtual array in a virtual file that has associated FIELD variables, causes BASIC to signal "Illegal operation" (ERR=141).
  5. If you name an array in a FIELD statement, you cannot use MAT statements in the following format:


    MAT array-name1 = array-name2 
    MAT array-name1 = NUL$ 
    

    where array-name1 is named in a FIELD statement. This causes BASIC to signal a compile-time error.


Example


FIELD #8%, 2% AS U$, 2% AS CL$, 4% AS X$, 4% AS Y$ 
LSET U$ = CVT%$(U%) 
LSET CL$ = CVT%$(CL%) 
LSET X$ = CVTF$(X) 
LSET Y$ = CVTF$(Y) 
U% = CVT$%(U$) 
CL% = CVT$%(CL$) 
X = CVT$F(X$) 
Y = CVT$F(Y$) 


FIND

The FIND statement locates a specified record in a disk file and makes it the current record for a GET, UPDATE, or DELETE operation. FIND statements are valid on RMS sequential, relative, and indexed files.

Format



Syntax Rules

  1. Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).
  2. If you specify a lock-clause, it must follow the position-clause. If the lock-clause precedes the position-clause, BASIC signals an error.
  3. If you specify the REGARDLESS lock-clause, you cannot specify another lock-clause in the same FIND statement.

Remarks

  1. Position-clause
  2. Lock-clause
  3. Key-clause
  4. Rel-op
  5. Key-exp
  6. The file on the specified channel must have been opened with ACCESS MODIFY, ACCESS READ, or SCRATCH before your program can execute a FIND operation.
  7. FIND does not transfer any data to the record buffer. To access the contents of a record, use the GET statement.
  8. A successful sequential FIND operation updates both the current record pointers and next record pointers.
  9. A successful random access FIND operation by RFA or by record changes the current record pointer to the record specified by rfa-exp or int-exp, but leaves the next record pointer unchanged.
  10. A successful random access FIND operation by key changes the current record pointer to the first record whose key satisfies the key-clause comparison and leaves the next record pointer unchanged.
  11. When a random access FIND operation by RFA, record, or key is not successful, BASIC signals "Record not found" (ERR=155). The values of the current record pointer and next record pointer are undefined.
  12. You should not use a FIND statement on a terminal-format or virtual array file.

Example


Previous Next Contents Index