HP OpenVMS Systems Documentation

Content starts here


Reference Manual

Order Number: AA--HY16F-TK

January 2005

This manual provides reference, syntax, and language element information for HP BASIC running on HP OpenVMS Industry Standard 64 or HP OpenVMS Alpha systems.

Revision/Update Information: This revised manual supersedes the Compaq BASIC for OpenVMS Alpha and VAX Systems Reference Manual, Version 1.4.

Software Version: HP BASIC Version 1.6
for OpenVMS Systems

Operating System: OpenVMS I64 Version 8.2 or higher
OpenVMS Alpha Version 7.1 or higher
(with IEEE floating-point support)
OpenVMS Alpha Version 6.1 or higher
(without IEEE floating-point support)

Hewlett-Packard Company Palo Alto, California

© Copyright 2005 Hewlett-Packard Development Company, L.P.

Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license.

The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein.

Intel and Itanium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

Printed in the US


Contents Index


This manual describes BASIC language elements and syntax.


In this manual, the term OpenVMS refers to both OpenVMS I64 and OpenVMS Alpha systems. If there are differences in the behavior of the HP BASIC compiler on the two operating systems, those differences are noted in the text.

The term I64 BASIC refers to HP BASIC on OpenVMS I64 systems.

Alpha BASIC refers to HP BASIC on OpenVMS Alpha systems.

VAX BASIC refers to VAX BASIC on OpenVMS VAX systems.

Intended Audience

This manual is intended for experienced applications programmers who have a fundamental understanding of the BASIC language. Some familiarity with your operating system is also recommended. This is not a tutorial manual.

Document Structure

This manual contains the following chapters and appendixes:

  • Chapter 1 summarizes HP BASIC program elements and structure.
  • Chapter 2 describes the compiler directives.
  • Chapter 3 describes the statements and functions.
  • Appendix A lists the ASCII codes.
  • Appendix B lists the HP BASIC keywords.
  • Appendix C discusses differences between HP BASIC on OpenVMS I64 and Alpha systems and differences between HP BASIC on OpenVMS I64/Alpha systems and OpenVMS VAX systems.

Related Documents

For detailed information about developing, compiling, linking, and running BASIC programs, see the HP BASIC for OpenVMS User Manual.

Reader's Comments

HP welcomes your comments on this manual. Please send comments to either of the following addresses:

Internet openvmsdoc@hp.com
Postal Mail Hewlett-Packard Company
OSSG Documentation Group, ZKO3-4/U08
110 Spit Brook Rd.
Nashua, NH 03062-2698


The following product names may appear in this manual:

  • HP OpenVMS Industry Standard 64 for Integrity Servers
  • OpenVMS I64
  • I64

All three names---the longer form and the two abbreviated forms---refer to the version of the OpenVMS operating system that runs on the Intel® Itanium® architecture.

The following typographic conventions might be used in this manual:

Ctrl/ x A sequence such as Ctrl/ x indicates that you must hold down the key labeled Ctrl while you press another key or a pointing device button.
PF1 x A sequence such as PF1 x indicates that you must first press and release the key labeled PF1 and then press and release another key or a pointing device button.
[Return] In examples, a key name enclosed in a box indicates that you press a key on the keyboard. (In text, a key name is not enclosed in a box.)

In the HTML version of this document, this convention appears as brackets, rather than a box.

... A horizontal ellipsis in examples indicates one of the following possibilities:
  • Additional optional arguments in a statement have been omitted.
  • The preceding item or items can be repeated one or more times.
  • Additional parameters, values, or other information can be entered.
A vertical ellipsis indicates the omission of items from a code example or command format; the items are omitted because they are not important to the topic being discussed.
( ) In command format descriptions, parentheses indicate that you must enclose choices in parentheses if you specify more than one.
[ ] In command format descriptions, brackets indicate optional choices. You can choose one or more items or no items. Do not type the brackets on the command line. However, you must include the brackets in the syntax for OpenVMS directory specifications and for a substring specification in an assignment statement.
| In command format descriptions, vertical bars separate choices within brackets or braces. Within brackets, the choices are optional; within braces, at least one choice is required. Do not type the vertical bars on the command line.
{ } In command format descriptions, braces indicate required choices; you must choose at least one of the items listed. Do not type the braces on the command line.
bold type Bold type represents the introduction of a new term. It also represents the name of an argument, an attribute, or a reason.
italic type Italic type indicates important information, complete titles of manuals, or variables. Variables include information that varies in system output (Internal error number), in command lines (/PRODUCER= name), and in command parameters in text (where dd represents the predefined code for the device type).
UPPERCASE TYPE Uppercase type indicates a command, the name of a routine, the name of a file, or the abbreviation for a system privilege.
- A hyphen at the end of a command format description, command line, or code line indicates that the command or statement continues on the following line.
numbers All numbers in text are assumed to be decimal unless otherwise noted. Nondecimal radixes---binary, octal, or hexadecimal---are explicitly indicated.

Mnemonics and Other Terms Used in Syntax Diagrams

angle Angle in radians or degrees
array Array; syntax rules specify whether the bounds or dimensions can be specified
chnl I/O channel associated with a file
chnl-exp Numeric expression that specifies a channel number
com Specific to a COMMON block
cond Conditional expression; indicates that an expression can be either logical or relational
cond-exp Conditional expression
const Constant value
data-type Data type keyword
decimal-var Decimal variable
decl-item Array, record, or variable
def Specific to a DEF function
delim Delimiter
equiv-name File specification, device, or logical name to be assigned a logical name
err-num Run-time error number
exp Expression
ext-routine External function
external-param External parameter
file-spec File specification
func Specific to a FUNCTION subprogram
int Integer value
int-const Integer constant
int-exp Expression that represents an integer value
int-var Variable that contains an integer value
label Alphanumeric statement label
lex Lexical; used to indicate a component of a compiler directive
lex-exp Lexical expression
lex-var Lexical variable
line Statement line; may or may not be numbered
line-num Statement line number
lit Literal value, in quotation marks
log-exp Logical expression
log-name 1- to 63-character logical name to be associated with equiv-name
macro-id User identifier following the rules for BASIC identifiers
map Specific to a MAP statement
matrix Two-dimensional array
name Name or identifier; indicates the declaration of a name or the name of a BASIC structure, such as a SUB subprogram
num Numeric value
num-lit Numeric literal
param-list Parameter list, such as for a SUB subprogram
pass-mech Valid BASIC passing mechanism
prog-name Program name
real Floating-point value
real-exp Real expression
real-var Real variable
rec-exp Record expression; record number within a file
rel-exp Relational expression
relationship-type Oracle CDD/Repository protocol
replacement-token Identifier, keyword, compiler directive, literal constant, or operator
routine SUB subprogram or other callable procedure
str Character string
str-exp Expression that represents a character string
str-lit String literal
str-var Variable that contains a character string
sub Specific to a SUB subprogram
target Target point of a branch statement; either a line number or a label
unq-str Unique string
unsubs-var Unsubscripted variable, as opposed to an array element
var Variable

Chapter 1
Program Elements and Structure

This chapter discusses BASIC program elements and structure.

1.1 Building Blocks

The building blocks of a BASIC program are:

  • Program lines and their components
  • The BASIC character set
  • BASIC data types
  • Variables and constants
  • Expressions
  • Program documentation

1.2 Components of Program Lines

A BASIC program is a series of program lines that contain instructions for the compiler.

All BASIC program lines can contain the following:

  • Line numbers or labels
  • Statements
  • Compiler directives
  • Comment fields
  • A line terminator (carriage return)

Only a line terminator is required in a program line. The other elements are optional.

A program line can contain any number of text lines. A text line cannot exceed 255 characters.

1.2.1 Line Numbers

Line numbers are not required in programs; you can compile, link, and execute a program with or without line numbers. There are, however, different rules for writing programs with line numbers and for writing programs without line numbers. These differences are described in the following sections. Programs with Line Numbers

A line number must be a unique integer from 1 through 32767, and must be terminated by a space or tab. Leading spaces, tabs, and zeros in line numbers are ignored. Embedded spaces, tabs, and commas cause BASIC to signal an error. Programs that use line numbers must have a line number associated with the first program line. Programs Without Line Numbers

BASIC searches for a line number on the first line of program text.

If no line number is found, then the following rules apply:

  • No line numbers are allowed in that program module.
  • References to the ERL function are not allowed.
  • A subroutine will signal the same errors as it would if it were compiled with the /NOLINES qualifier. If an error is resignaled back to the caller, ERL gives the line number of the calling site, rather than the line number of the actual error in the subprogram.
  • The REM statement is not allowed.

If your program contains multiple units, the point at which BASIC breaks each program unit is determined by the placement of the statement that terminates each program unit. Any text that follows the program terminator becomes associated with the the following program unit. A program terminator can be END, END PROGRAM, END FUNCTION, or END SUB.

Note that program statements can begin in the first column.

Instead of line numbers, you can use labels to identify and reference program lines.

1.2.2 Labels

A label is a 1- to 31-character name that identifies a statement or block of statements. The label name must begin with a letter; the remaining characters, if any, can be any combination of letters, digits, dollar signs ($), underscores (_), or periods (.).

A label name must be separated from the statement it identifies with a colon (:). For example:

Yes_routine: PRINT "Your answer is YES."

The colon is not part of the label name; it informs BASIC that the label is being defined rather than referenced. Consequently, the colon is not allowed when you use a label to reference a statement. For example:

200     GOTO Yes_routine

You can reference a label almost anywhere you can reference a line number. However, there are the following exceptions:

  • You cannot compare a label with the value returned by the ERL function.
  • You cannot reference a label in an IF...THEN...ELSE statement without using the keyword GOTO or GO TO. You can use the implied GOTO form only to reference a line number. In Example 1-1, the GOTO keyword is not required in statement 100 because the reference is to a line number. However, the GOTO keyword is required in statement 200 because the references are to labels.

    Example 1-1 Referencing Label Names in BASIC Programs

    100 IF A% = B%
        THEN 1000 ELSE 1050
    200 IF A$ = "YES"

1.2.3 Statements

A BASIC statement generally consists of a statement keyword and optional operators and operands. For example, both of the following statements are valid:

LET A% = 534% + (SUM% - DIF%)

BASIC statements can be either executable or nonexecutable:

  • Executable statements perform operations (for example, PRINT, GOTO, and READ).
  • Nonexecutable statements describe the characteristics and arrangement of data, specify usage information, and serve as comments in the source program (for example, DATA, DECLARE, and REM).

BASIC can accept and process one statement on a line of text, several statements on a line of text, multiple statements on multiple lines of text, and single statements continued over several lines of text. Keywords

Every BASIC statement except LET1 and empty statements must begin with a keyword. Most keywords are reserved in the BASIC language. The keywords are listed in Appendix B, and the unreserved keywords are footnoted. Keywords are used to do the following:

  • Define data and user identifiers
  • Perform operations
  • Invoke built-in functions

Reserved keywords cannot be used as user identifiers, such as variable names, labels, or names for MAP or COMMON areas. Reserved keywords cannot be used in any context other than as BASIC keywords. The assignment STRING$ = "YES", for example, is invalid because STRING$ is a reserved BASIC keyword and, therefore, cannot be used as a variable. See Appendix B for a list of all the BASIC keywords.

A BASIC keyword cannot be split across lines of text. There must be a space, tab, or special character such as a comma between the keyword and any other variable or operator.

Some keywords use two words, and some can be combined with other keywords. Their spacing requirements vary, as shown in Table 1-1.

Table 1-1 Keyword Space Requirements
Optional Space Required Space No Space


1 The LET keyword is optional.

Next Contents Index