Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


ON...GOTO

The ON...GOTO statement transfers program control to one of several lines or targets, depending on the value of a control expression.

Format



Syntax Rules

  1. Int-exp determines which target BASIC selects as the GOTO argument. If int-exp equals 1, BASIC selects the first target. If int-exp equals 2, BASIC selects the second target, and so on.
  2. Target must be a valid BASIC line number or a label and must exist in the current program unit.

Remarks

  1. Control cannot be transferred into a statement block (such as FOR...NEXT, UNTIL...NEXT, WHILE...NEXT, DEF...END DEF, SELECT...END SELECT, WHEN...END WHEN, or HANDLER...END HANDLER).
  2. If there is an OTHERWISE clause, and if int-exp is less than one or greater than the number of targets in the list, BASIC transfers control to the target of the OTHERWISE clause.
  3. If there is no OTHERWISE clause, and if int-exp is less than 1 or greater than the number of line numbers in the list, BASIC signals "ON statement out of range" (ERR=58).
  4. If a target specifies a nonexecutable statement, BASIC transfers control to the first executable statement that lexically follows the target.
  5. You can only use the ON...GOTO statement inside a handler if all the targets are contained within the handler.
  6. You can specify the ON...GOTO statement inside a WHEN block if the ON...GOTO target is in the same protected region, an outer protected region, or in a nonprotected region.
  7. You cannot specify an ON...GOTO statement inside a WHEN block if the ON...GOTO target already resides in another protected region that does not contain the most current protected region.

Example


ON INDEX% GOTO 700,800,900 OTHERWISE finish 
   .
   .
   .
finish: 
    END PROGRAM 


OPEN

The OPEN statement opens a file for processing. It transfers user-specified file characteristics to OpenVMS Record Management Services (RMS) and verifies the results.

Format



Syntax Rules

  1. File-spec1 specifies the file to be opened and associated with chnl-exp. It can be any valid string expression and must be a valid VMS file specification. BASIC passes these values to RMS without editing, alteration, or validity checks.
    BASIC does not supply any default file specifications, unless you include the DEFAULTNAME clause in the OPEN statement.
  2. The FOR clause determines how BASIC opens a file.
  3. Chnl-exp is a numeric expression that specifies a channel number to be associated with the file being opened. It can be preceded by an optional number sign (#) and must be in the range of 1 to 119. Note that channels 100 to 119 are usually reserved for allocation by the RTL routines, LIB$GET_LUN and LIB$FREE_LUN.
  4. A statement that accesses a file cannot execute until you open that file and associate it with a channel.

Remarks

  1. The OPEN statement does not retrieve records.
  2. Channel #0, the terminal, is always open. If you try to open channel zero, BASIC signals the error "Illegal I/O channel" (ERR=46).
  3. If a program opens a file on a channel already associated with an open file, BASIC closes the previously opened file and opens the new one.
  4. The ACCESS clause determines how the program can use the file.
    For an illustration of the interaction of ACCESS and ALLOW, see No. 5.
  5. The ALLOW clause can be used in the OPEN statement to specify file sharing of relative, indexed, sequential, and virtual files.
    The following scenario may help clarify the interaction of the ACCESS and ALLOW clauses: Suppose you specify ACCESS WRITE and ALLOW READ for a file. Your program then can access and write to the file, but other users (both new and preexisting) can only read the file. However, if another user has already opened the file for writing, an error is signaled. For further information, refer to the OpenVMS Record Management Services (RMS) documentation.
  6. The BUFFER clause can be used with all file organizations except UNDEFINED.
  7. The CONTIGUOUS clause causes RMS to try to create the file as a contiguous-best-try sequence of disk blocks. The CONTIGUOUS clause does not affect existing files or nondisk files.
    The CONTIGUOUS clause does not guarantee that the file will occupy contiguous disk space. If RMS can locate the file in a contiguous area, it will do so. However, if there is not enough free contiguous space for a file, RMS allocates the largest possible contiguous space and does not signal an error. See the OpenVMS Record Management Services Reference Manual for more information about contiguous disk allocation.
  8. The DEFAULTNAME clause lets you supply a default file specification. If file-spec1 is not a complete file specification, file-spec2 in the DEFAULTNAME clause supplies the missing parts. For example:


    10      INPUT 'FILE NAME';fnam$ 
    20      OPEN fnam$ FOR INPUT AS FILE #1%,   & 
                        DEFAULTNAME "USER$$DISK:.DAT" 
    

    If you type "ABC" for the file name, BASIC tries to open
    USER$$DISK:[]ABC.DAT.

  9. The EXTENDSIZE clause lets you specify the increment by which RMS extends a file after its initial allocation is filled. The value of int-exp5 is in 512-byte disk blocks. The EXTENDSIZE clause has no effect on an existing file.
  10. The FILESIZE clause lets you pre-extend a new file to a specified size.
  11. The MAP clause specifies that a previously declared map is associated with the file's record buffer. The MAP clause determines the record buffer's address and length unless overridden by the RECORDSIZE clause.
  12. The ORGANIZATION clause specifies the file organization. When present, it must precede all other clauses. When you specify an ORGANIZATION clause, you must also specify one of the following organization options: VIRTUAL, UNDEFINED, INDEXED, SEQUENTIAL or RELATIVE. Specify ORGANIZATION UNDEFINED if you do not know the actual organization of the file. If you do not specify an ORGANIZATION clause, BASIC opens a terminal format file by default.
  13. The RECORDSIZE clause specifies the file's record size. Note that there are restrictions on the maximum record size allowed for various file and record formats. See the OpenVMS Record Management Services Reference Manual for more information.
  14. The RECORDTYPE clause specifies the file's record attributes.
  15. The TEMPORARY clause causes BASIC to delete the output file as soon as the program closes it.
  16. The UNLOCK EXPLICIT clause allows you to retain locks on records until they are explicitly unlocked.
  17. The USEROPEN clause lets you open a file with your own FUNCTION subprogram.

    Note

    Future releases of the OpenVMS Run-Time Library may alter the use of some RMS fields. Therefore, you may have to alter your USEROPEN procedures accordingly.
  18. The WINDOWSIZE clause followed by int-exp3 lets you specify the number of block retrieval pointers you want to maintain in memory for the file.
    Retrieval pointers are associated with the file header and point to contiguous blocks on disk.
  19. The BLOCKSIZE clause specifies the physical block size of magnetic tape files. The BLOCKSIZE clause can be used for magnetic tape files only.
  20. The NOREWIND clause controls tape positioning on magnetic tape files. The NOREWIND clause can be used for magnetic tape files only.
  21. The NOSPAN clause specifies that sequential records cannot cross block boundaries.
  22. The BUCKETSIZE clause applies only to relative and indexed files. It specifies the size of an RMS bucket in terms of the number of records one bucket should hold.
  23. The CONNECT clause permits multiple record streams to be connected to the file.
  24. The PRIMARY KEY clause lets you specify an indexed file's key. You must specify a primary key when opening an indexed file. The ALTERNATE KEY clause lets you specify up to 254 alternate keys. The ALTERNATE KEY clause is optional.

Examples

Example 1


OPEN "FILE.DAT" AS FILE #4 

Example 2


OPEN "INPUT.DAT" FOR INPUT AS FILE #4,                  & 
         ORGANIZATION SEQUENTIAL FIXED,                 & 
         RECORDSIZE 200,                                & 
         MAP ABC,                                       & 
         ALLOW MODIFY, ACCESS MODIFY 
 
 
OPEN Newfile$ FOR OUTPUT AS FILE #3,                    & 
         INDEXED VARIABLE,                              & 
         MAP Emp_name,                                  & 
         DEFAULTNAME "USER$$DISK:.DAT",                 & 
         PRIMARY KEY Last$ DUPLICATES,                  & 
         ALTERNATE KEY First$ CHANGES 
 
 
MAP (SEGKEY) STRING last_name = 15,                     & 
          MI = 1, first_name = 15 
 
OPEN "NAMES.IND" FOR OUTPUT AS FILE #1,                 & 
         ORGANIZATION INDEXED,                          & 
         PRIMARY KEY (last_name, first_name, MI),       & 
         MAP SEGKEY 


Previous Next Contents Index