Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


DECLARE LONG rec-num 
MAP (cusrec) WORD cus_num                                   & 
    STRING cus_nam=20, cus_add=20, cus_city=10,  cus_zip=9 
OPEN "CUS_ACCT.DAT" FOR INPUT AS #1,                        & 
      RELATIVE FIXED,                                       & 
      ACCESS MODIFY                                         & 
      MAP cusrec 
INPUT "Which record number would you like to delete";rec_num 
FIND #1, RECORD rec_num, WAIT 
DELETE #1 
CLOSE #1 
END 


FIX

The FIX function truncates a floating-point value at the decimal point and returns the integer portion represented as a floating-point value.

Format



Syntax Rules

None


Remarks

  1. The FIX function returns the integer portion of a floating-point value, not an integer value.
  2. BASIC expects the argument of the FIX 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. If real-exp is negative, FIX returns the negative integer portion. For example, FIX(-5.2) returns -5.

Example


DECLARE SINGLE result 
result = FIX(-3.333) 
PRINT FIX(24.566), result 

Output


 24          -3 


FNEND

The FNEND statement is a synonym for the END DEF statement. See the END statement for more information.

Format



FNEXIT

The FNEXIT statement is a synonym for the EXIT DEF statement. See the EXIT statement for more information.

Format



FOR

The FOR statement repeatedly executes a block of statements, while incrementing a specified control variable for each execution of the statement block. FOR loops can be conditional or unconditional, and can modify other statements.

Format



Syntax Rules

  1. Num-unsubs-var must be a numeric, unsubscripted variable. Num-unsubs-var cannot be a record field.
  2. Num-unsubs-var is the loop variable. It is incremented each time the loop executes.
  3. In unconditional FOR loops, num-exp1 is the initial value of the loop variable; num-exp2 is the maximum value.
  4. In conditional FOR loops, num-exp1 is the initial value of the loop variable, while the cond-exp in the WHILE or UNTIL clause is the condition that controls loop iteration.
  5. Num-exp3 in the STEP clause is the value by which the loop variable is incremented after each execution of the loop.

Remarks

  1. There is a limit to the number of inner loops you can contain within a single outer loop. This number varies according to the complexity of the loops. If you exceed the limit, BASIC signals an error message.
  2. An inner loop must be entirely within an outer loop; the loops cannot overlap.
  3. You cannot use the same loop variable in nested FOR loops. For example, if the outer loop uses FOR I = 1 TO 10, you cannot use the variable I as a loop variable in an inner loop.
  4. The default for num-exp3 is 1 if there is no STEP clause.
  5. You can transfer control into a FOR loop only by returning from a function invocation, a subprogram call, a subroutine call, or an error handler that was invoked in the loop.
  6. The starting, incrementing, and ending values of the loop do not change during loop execution.
  7. The loop variable can be modified inside the FOR loop.
  8. BASIC converts num-exp1, num-exp2, and num-exp3 to the data type of the loop variable before storing them.
  9. When an unconditional FOR loop ends, the loop variable contains the value last used in the loop, not the value that caused loop termination.
  10. During each iteration of a conditional loop, BASIC tests the value of cond-exp before it executes the loop.
  11. When FOR is used as a statement modifier, BASIC executes the statement until the loop variable equals or exceeds num-exp2 or until the WHILE or UNLESS condition is satisfied.
  12. Each FOR statement must have a corresponding NEXT statement or BASIC signals an error. (This is not the case if the FOR statement is used as a statement modifier.)

Examples

Example 1


!Unconditional 
DECLARE LONG course_num, STRING course_nam 
FOR I = 3 TO 12 STEP 3 
INPUT "Course number";course_num 
INPUT "Course name";course_nam 
NEXT I 

Output


Course number? 221 
Course name? Botany 
Course number? 231 
Course name? Organic Chemistry 
Course number? 237 
Course name? Life Science II 
Course number? 244 
Course name? Programming in BASIC

Example 2


!Unconditional Statement Modifier 
DECLARE INTEGER counter 
PRINT "This is an unconditional statement modifier" FOR counter = 1 TO 3 
END 

Output


This is an unconditional statement modifier 
This is an unconditional statement modifier 
This is an unconditional statement modifier 

Example 3


!Conditional Statement Modifier 
DECLARE INTEGER counter, & 
        STRING my_name 
INPUT "Try and guess my name";my_name FOR counter = 1 UNTIL my_name = "BASIC" 
PRINT "You guessed it!" 

Output


Try and guess my name? VAX PASCAL 
Try and guess my name? VAX SCAN 
Try and guess my name? BASIC
You guessed it! 


FORMAT$

The FORMAT$ function converts an expression to a formatted string.

Format



Syntax Rules

The rules for building a format string are the same as those for printing numbers with the PRINT USING statement. See the description of the PRINT USING statement for more information.


Remarks

It is recommended that you use compile-time constant expressions for string expressions whenever possible. When you do this, the BASIC compiler compiles the string at compilation time rather than at run time, thus improving the performance of your code.


Example


DECLARE STRING result,         & 
        INTEGER num_exp 
num_exp = 12345 
result = FORMAT$(num_exp,"##,###") 
PRINT result 

Output


12,345 


FREE

The FREE statement unlocks all records and buckets associated with a specified channel.

Format



Syntax Rules

Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).


Remarks

  1. The file specified by chnl-exp must be open.
  2. You cannot use the FREE statement with files not on disk.
  3. If there are no locked records or buckets on the specified channel, the FREE statement has no effect and BASIC does not signal an error.
  4. The FREE statement does not change record buffers or pointers.
  5. After a FREE statement has executed, your program must execute a GET or FIND statement before a PUT, UPDATE, or DELETE statement can execute successfully.

Example


OPEN "CUST_ACCT.DAT" FOR INPUT AS #3 
   .
   .
   .
INPUT "Enter customer record number to retrieve";cust_rec_num 
FREE #3 
GET #3 

In this example, CUST_ACCT.DAT is opened for input. The FREE statement unlocks all records associated with the specified channel contained in the file. Once the FREE statement successfully executes, the user can then obtain a record with either a FIND or GET statement.


FSP$

The FSP$ function returns a string describing an open file on a specified channel.

Format



Syntax Rules

  1. A file must be open on chnl-exp.
  2. The FSP$ function must come immediately after the OPEN statement for the file.

Remarks

  1. Use the FSP$ function with files opened as ORGANIZATION UNDEFINED. Then use multiple MAP statements to interpret the returned data.
  2. See the Compaq BASIC for OpenVMS Alpha and VAX Systems User Manual and the OpenVMS Record Management Services Reference Manual for more information about FSP$ values.

    Note

    BASIC supports the FSP$ function for compatibility with BASIC-PLUS-2. It is recommended that you use the USEROPEN routine to identify file characteristics.

Example


10 MAP (A) STRING A = 32 
   MAP (A) BYTE org, rat, WORD mrs, LONG alq,  & 
           WORD bks_bls, num_keys,LONG mrn 
   OPEN "STUDENT.DAT" FOR INPUT AS #1%,        & 
         ORGANIZATION UNDEFINED,               & 
         RECORDTYPE ANY, ACCESS READ 
   A = FSP$(1%) 
   PRINT "RMS organization = ";org 
   PRINT "RMS record attributes = ";rat 
   PRINT "RMS maximum record size = ";mrs 
   PRINT "RMS allocation quantity = ";alq 
   PRINT "RMS bucket size = ";bks_bls 
   PRINT "Number of keys = ";num_keys 
   PRINT "RMS maximum record number = ";mrn 

Output


RMS organization = 2 
RMS record attributes = 2 
RMS maximum record size = 5 
RMS allocation quantity = 1 
RMS bucket size = 0 
Number of keys = 0 
RMS maximum record number = 0 


FUNCTION

The FUNCTION statement marks the beginning of a FUNCTION subprogram and defines the subprogram's parameters.

Format



Syntax Rules

  1. Note that both Alpha BASIC and VAX BASIC are able to pass actual parameters by value, but only Alpha BASIC allows formal parameters to be passed in by value. This means that while Alpha BASIC can use BY VALUE in a definition and a call, VAX BASIC can use BY VALUE only in a call. It cannot define a function that takes parameters BY VALUE.
  2. Func-name names the FUNCTION subprogram.
  3. Func-name can be from 1 through 31 characters. The first character 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 (_).
  4. Data-type can be any BASIC data type keyword or a data type defined in the RECORD statement. Data type keywords, size, range, and precision are listed in Table 1-2.
  5. The data type that precedes the func-name specifies the data type of the value returned by the function.
  6. Formal-param specifies the number and type of parameters for the arguments the function expects to receive when invoked.
  7. Pass-mech specifies the parameter-passing mechanism by which the FUNCTION subprogram receives arguments when invoked. A pass-mech clause should be specified only when the FUNCTION subprogram is being called by a non BASIC program or when the FUNCTION receives a string or array by reference.
  8. A pass-mech clause outside the parentheses applies by default to all function parameters. A pass-mech clause in the formal-param list overrides the specified default and applies only to the immediately preceding parameter.
  9. Exp specifies the function result, which supersedes any function assignment. Exp must be compatible with the function's data type.

Remarks

  1. The FUNCTION statement must be the first statement in the FUNCTION subprogram.
  2. Every FUNCTION statement must have a corresponding END FUNCTION or FUNCTIONEND statement.
  3. Any BASIC statement except END, PICTURE, END PICTURE, PROGRAM, END PROGRAM, SUB, SUBEND, END SUB, or SUBEXIT can appear in a FUNCTION subprogram.
  4. FUNCTION subprograms must be declared with the EXTERNAL statement before your BASIC program can invoke them.
  5. FUNCTION subprograms receive parameters by reference, by descriptor, or by value.
  6. By default, FUNCTION subprograms receive numeric unsubscripted variables by reference, and all other parameters by descriptor. You can override these defaults with a BY clause:
  7. All variables and data, except virtual arrays, COMMON areas, MAP areas, and EXTERNAL variables, in a FUNCTION subprogram, are local to the subprogram.
  8. BASIC initializes local numeric variables to zero and local string variables to the null string each time the FUNCTION subprogram is invoked.
  9. If an exception is not handled within the FUNCTION subprogram, control is transferred back to the main program that invoked the function.

Example


FUNCTION REAL sphere_volume (REAL R) 
IF R < 0 THEN EXIT FUNCTION 
sphere_volume = 4/3 * PI *R **3 
END FUNCTION 


FUNCTIONEND

The FUNCTIONEND statement is a synonym for the END FUNCTION statement. See the END statement for more information.

Format



FUNCTIONEXIT

The FUNCTIONEXIT statement is a synonym for the EXIT FUNCTION statement. See the EXIT statement for more information.

Format



GET

The GET statement copies a record from a file to a record buffer and makes the data available for processing. GET statements are valid on 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 GET statement.

Remarks

  1. Position-clause
  2. Lock-clause
  3. Key-clause
  4. Rel-op
  5. Key-exp
  6. The file specified by chnl-exp must be opened with ACCESS READ or ACCESS MODIFY or SCRATCH before your program can execute a GET statement. The default ACCESS clause is MODIFY.
  7. If the last I/O operation was a successful FIND operation, a sequential GET operation retrieves the current record located by the FIND operation and sets the next record pointer to the record logically succeeding the pointer.
  8. If the last I/O operation was not a FIND operation, a sequential GET operation retrieves the next record and sets the record logically succeeding the record pointer to the current record.
  9. A successful random GET operation by RFA or by record retrieves the record specified by rfa-exp or int-exp.
  10. A successful random GET operation by key retrieves the first record whose key satisfies the key-clause comparison.
  11. A successful random GET operation by RFA, record, or key sets the value of the current record pointer to the record just read. The next record pointer is set to the next logical record.
  12. An unsuccessful GET operation leaves the record pointers and the record buffer in an undefined state.
  13. If the retrieved record is smaller than the receiving buffer, BASIC fills the remaining buffer space with nulls.
  14. If the retrieved record is larger than the receiving buffer, BASIC truncates the record and signals an error.
  15. A successful GET operation sets the value of the RECOUNT variable to the number of bytes transferred from the file to the record buffer.
  16. You should not use a GET statement on a terminal-format or virtual array file.

Example


Previous Next Contents Index