[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP BASIC for OpenVMS
Reference Manual


Previous Contents Index

1.2.3.2 Single-Statement Lines and Continued Statements

A single-statement line consists of one statement on one text line, or one statement continued over two or more text lines. For example:


30 PRINT B * C / 12

This single-statement line has a line number, the keyword (PRINT), the operators (*, /), and the operands (B, C, 12).

You can have a single statement span several text lines by typing an ampersand (&) and pressing the Return key. Note that only spaces or tabs are valid between the ampersand and the carriage return. For example:


OPEN "SAMPLE.DAT" AS FILE 2%,         &
         SEQUENTIAL VARIABLE,         &
         MAP ABC

The ampersand continuation character may be used but is not required for continued REM statements. The following example is valid:


REM This is a remark
    And this is also a remark

You can continue any BASIC statement, but you cannot continue a string literal or BASIC keyword. The following example generates the error message "Unterminated string literal":


PRINT "IF-THEN-ELSE- &
       END-IF"

This example is valid:


PRINT "IF-";         &
      "THEN-";       &
      "ELSE-";       &
      "END-";        &
      "IF"

1.2.3.3 Multistatement Lines

Multistatement lines contain several statements on one line of text or multiple statements on separate lines of text.

Multiple statements on one line of text must be separated by a backslash (\) character. For example:


40 PRINT A \ PRINT V \ PRINT G

You can also write a multistatement program line that associates all statements with a single line number by placing each statement on a separate line. BASIC assumes that such an unnumbered line of text is either a new statement or an IF statement clause.

In the following example, each line of text begins with a BASIC statement and each statement is associated with line number 400:


400   PRINT A
      PRINT B
      PRINT "FINISHED"

BASIC also recognizes IF statement keywords on a new line of text and associates such keywords with the preceding IF statement. For example:


100  REM        Determine if the user's response
                was YES or NO.
200  IF (A$ = "YES") OR (A$ = "Y")
     THEN PRINT "You typed YES"
     ELSE PRINT "You typed NO"
     STOP
     END IF

You can use any BASIC statement in a multistatement line. Because the compiler ignores all text following a REM keyword until it reaches a new line number, a REM statement must be the last statement on a multistatement line. REM statements are disallowed in programs without line numbers.

1.2.4 Compiler Directives

Compiler directives are instructions for the compiler. These instructions cause the compiler to perform certain operations as it compiles the program.

By including compiler directives in a program, you can do the following:

  • Place program titles and subtitles in the header that appears on each page of the listing file.
  • Place a program version identification string in both the listing file and object module.
  • Start or stop the inclusion of listing information for selected parts of a program.
  • Start or stop the inclusion of cross reference information for selected parts of a program.
  • Include BASIC code from another source file or a text library.
  • Conditionally compile parts of a program.
  • Terminate compilation.
  • Include CDD record definitions in a BASIC program.
  • Display messages during the compilation.

Follow these rules when using compiler directives:

  • Compiler directives must begin with a percent sign (%).
  • Compiler directives must be the only text on the line (except for%IF-%THEN-%ELSE-%END-%IF).
  • Compiler directives cannot appear within a quoted string.
  • Compiler directives can be preceded by an optional line number.

For more information about compiler directives, see the HP BASIC for OpenVMS User Manual.

1.3 BASIC Character Set

BASIC uses the full ASCII character set. This includes the following:

  • The letters A to Z, both uppercase and lowercase
  • The digits 0 to 9
  • Special characters

Appendix A lists the full ASCII character set and character values.

The compiler does not distinguish between uppercase and lowercase letters except in string literals or within a DATA statement. The compiler does not process characters in REM statements or comment fields, nor does it process nonprinting characters unless they are part of a string literal.

In string literals, BASIC processes:

  • Lowercase letters as lowercase
  • Nonprinting characters

The ASCII character NUL (ASCII code 0) and line terminators cannot appear in a string literal. Use the CHR$ function or explicit literal notation to use these characters and terminators.

You can use nonprinting characters in your program, for example, in string constants, but to do so you must use one of the following:

  • A predefined constant such as ESC or DEL
  • The CHR$ function to specify an ASCII value
  • Explicit literal notation

See Section 1.6.4 for more information about explicit literal notation.

1.4 BASIC Data Types

Each unit of data in a BASIC program has a specific data type that determines how that unit of data is to be interpreted and manipulated by the compiler. This data type also determines how many storage bits make up the unit of data.

BASIC recognizes the following primary data types:

  • Integer
  • Floating-point
  • Character string
  • Packed decimal
  • Record file address

Integer data is stored as binary values in a byte, word, longword, or quadword. These values correspond to the BASIC data type keywords BYTE, WORD, LONG, and QUAD; these are all subtypes of the type INTEGER.

Floating-point values are stored using a signed exponent and a binary fraction. BASIC allows the floating-point formats F_floating, D_floating, G_floating, S_floating, T_floating, and X_floating. These formats correspond to the BASIC data type keywords SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, and XFLOAT. These are all subtypes of the type REAL. (See Section 1.4.3.)

Character data consists of strings of bytes containing ASCII code as binary data. The first character in the string is stored in the first byte, the second character is stored in the second byte, and so on. BASIC allows up to 65,535 characters for a STRING data element.

For the DECIMAL(d,s) data type, you can specify the total number of digits (d) in the data type and the number of digits to the right of the decimal point (s). For example, DECIMAL(10,3) specifies decimal data with a total of 10 digits, 3 of which are to the right of the decimal point.

BASIC also recognizes a special RFA data type to provide information about a record's file address. An RFA uniquely specifies a record in a file: you can access RMS files of any organization by a record's file address. By specifying the address of a record, RMS retrieves the record at that address. Accessing records by RFA is more efficient and faster than other forms of random record access. The RFA data type can only be used for the following:

  • RFA operations (the GETRFA function and the GET and FIND statements)
  • Assignments to other variables of the RFA data type
  • Comparisons with other variables of the RFA data type with the equal to (=) and not equal to (<>) relational operators
  • Formal and actual parameters
  • DEF and function results

You cannot declare a constant of the RFA data type, nor can you use RFA variables for any arithmetic operations.

The RFA data type requires 6 bytes of information. See the HP BASIC for OpenVMS User Manual for more information about Record File Addresses and the RFA data type.

BASIC packed decimal data is stored in a string of bytes. See the HP BASIC for OpenVMS User Manual for more information about the storage of packed decimal data.

Table 1-2 summarizes HP BASIC data types.

Table 1-2 HP BASIC Data Types
Data Type Keyword Size Range Precision
(Decimal Digits)
Integer      
BYTE 8 bits (1 byte) -128 to +127 3
WORD 16 bits (2 bytes) -32768 to +32767 5
LONG 32 bits (4 bytes) -2147483648 to
+2147483647
10
QUAD 64 bits (8 bytes) -9223372036854775808 to
+9223372036854775807
19
Real      
SINGLE 32 bits (4 bytes) 0.29E-38 to 1.70E38 6
DOUBLE 64 bits (8 bytes) 0.29E-38 to 1.70E38 16
GFLOAT 64 bits (8 bytes) 0.56E-308 to 0.90E308 15
SFLOAT 32 bits (4 bytes) 1.18E-38 to 3.40E38 6
TFLOAT 64 bits (8 bytes) 2.23E-308 to 1.80E308 15
XFLOAT 128 bits (16 bytes) 6.48E-4966 to 1.19E4932 33
Decimal      
DECIMAL(d,s) 0 to 16 bytes ((d+1)/2 bytes) 1 * 10 -31 to 1 *10 31 d
String      
STRING One character per byte (default is 16 bytes) Max = 65535 NA
RFA      
RFA 6 bytes NA NA

In Table 1-2, REAL and INTEGER are generic data type keywords that specify floating-point and integer storage, respectively. If you use the REAL or INTEGER keywords to type data, the actual data type used (SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, XFLOAT, BYTE, WORD, LONG, or QUAD) depends on the current default.

You can specify data type defaults by doing the following:

  • Use the BASIC command at the DCL level.
  • Use the OPTION statement within the source program being compiled.

You can also specify whether program values are to be typed implicitly or explicitly. The following sections discuss data type defaults and implicit and explicit data typing.

1.4.1 Implicit Data Typing

You can implicitly assign a data type to program values by adding a suffix to the variable name or constant value. If you do not specify any suffix, the variable or constant is assigned the current default data type. The following rules apply for implicit data typing:

  • A dollar sign suffix ($) specifies STRING storage.
  • A percent sign suffix (%) specifies INTEGER storage.
  • No special suffix character specifies storage of the default type, which can be INTEGER, REAL, or DECIMAL.

With implicit data typing, the range and precision for program values are determined by the following corresponding default data sizes or subtypes:

  • BYTE, WORD, LONG, or QUAD for INTEGER values
  • SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, or XFLOAT for REAL values
  • The default (d,s) values for DECIMAL values

If you do not specify a value for the default data type, REAL will be assigned.

The qualifiers for the BASIC DCL command are listed in the HP BASIC for OpenVMS User Manual.

1.4.2 Explicit Data Typing

Explicit data typing means that you use a declarative statement to specify the data type, range, and precision of your program variables and named constants.

In the following example, the first DECLARE statement associates the string constant value 03060 and the STRING data type with a constant named zip_code. The second DECLARE statement associates the STRING data type with emp_name, the DOUBLE data type with with_tax, and the SINGLE data type with int_rate. No constant values are associated with identifiers in the second DECLARE statement because they are variable names.


DECLARE STRING CONSTANT zip_code = "03060"
DECLARE STRING emp_name, DOUBLE with_tax, SINGLE int_rate

With explicit data typing, each program variable within a program can have a different data type. You can explicitly assign data types to variables, constants, arrays, parameters, and functions; therefore, integer data does not have to take the compilation default types. Explicit data typing gives you more control over your program.

Using the REAL and INTEGER keywords to explicitly type program values allows you to write programs that are more flexible, because these data type keywords specify that floating-point and integer data take the current defaults for REAL and INTEGER. The data type INTEGER, for example, specifies only that the constant or variable is an integer. The actual subtype (BYTE, WORD, LONG, or QUAD) depends on the default set with the BASIC DCL command or with the OPTION statement.

1.4.3 QUAD and IEEE Floating-Point Data Types for 64-Bit Support

For 64-bit support, HP BASIC provides the QUAD data type for 64-bit integers as well as three IEEE floating-point types: SFLOAT, TFLOAT, and XFLOAT, which correspond to the S_floating, T_floating, and X_floating formats, respectively. QUAD and the IEEE data types are available wherever the other HP BASIC formats are available, as detailed in the following sections.

The three formats S_floating, T_floating, and X_floating are for finite values with normal rounding and standard exception handling only.

Qualifiers

The QUAD keyword is one of the allowed values of the /INTEGER_SIZE qualifier, and the SFLOAT, TFLOAT, and XFLOAT keywords are three of the allowed values of the /REAL_SIZE qualifier.

Statements, Expressions, Functions, and Operators

QUAD, SFLOAT, TFLOAT, and XFLOAT can be used in HP BASIC statements wherever a data type is supplied.

The INTEGER function, besides accepting either a numeric string or any numeric data type expression for the first argument, includes QUAD in the possible data types for the second argument. The REAL function has SFLOAT, TFLOAT, and XFLOAT added to possible data types for its second argument.

Data Type Results in Expressions with Operands of Different Types

See Section 1.7.1.1 and Section 1.7.1.2 for the rules determining the data types of results in expressions with operands of different data types.

Array Subscripts

Array subscripts may be of any numeric data type, but must evaluate to an integer value at run time.

1.5 Variables

A variable is a named quantity whose value can change during program execution. Each variable name refers to a location in the program's storage area. Each location can hold only one value at a time. Variables of all data types can have subscripts that indicate their position in an array. You can declare variables implicitly or explicitly.

Depending on the program operations specified, the value of a variable can change from statement to statement. HP BASIC uses the most recently assigned value when performing calculations. This value remains in effect until a new value is assigned to the variable.

HP BASIC accepts the following general types of variables:

  • Floating-point
  • Integer
  • String
  • RFA
  • Packed decimal
  • Record

1.5.1 Variable Names

The name given to a variable depends on whether the variable is internal or external to the program and whether the variable is implicitly or explicitly declared.

All variable names must conform to the following rules:

  • The name can have from 1 to 31 characters.
  • The name has no embedded spaces.
  • The first character of the name must be an uppercase or lowercase alphabetic character (A to Z).
  • The last character of the name can be a dollar sign ($) to indicate a string variable or a percent sign (%) to indicate an integer variable. If the last character is neither a dollar sign nor a percent sign, the name indicates a variable of the default type.
  • The remaining characters, if present, can be any combination of uppercase or lowercase letters (A to Z), numbers (0 to 9), dollar signs ($), underscores (_), or periods (.). The use of underscores in variable names helps improve readability and is preferred to the use of periods.

1.5.2 Implicitly Declared Variables

HP BASIC accepts the following implicitly declared variables:

  • Integer
  • String
  • Floating-point (or the default data type)

The name of an implicitly declared variable defines its data type. Integer variables end with a percent sign (%), string variables end with a dollar sign ($), and variables of the default type (usually floating-point) end with any allowable character except a percent sign or dollar sign. All three types of variables must conform to the rules listed in Section 1.5.1 for naming variables. The current data type default (INTEGER, REAL, or DECIMAL) determines the data type of implicitly declared variables that do not end in a percent sign or dollar sign.

A floating-point variable is a named location that stores a floating-point value. The current default size for floating-point numbers (SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, or XFLOAT) determines the data type of the floating-point variable.

Following are some examples of valid floating_point variable names:

C
M1
F67T_J
L...5
BIG47
Z2.
ID_NUMBER
STORAGE_LOCATION_FOR_XX
STRESS_VALUE

If a numeric value of a different data type is assigned to a floating-point variable, BASIC converts the value to a floating-point number.

An integer variable is a named location that stores an integer value. The current default size for integers (BYTE, WORD, LONG, or QUAD) determines the data type of an integer variable.

Following are some examples of valid integer variable names:

ABCDEFG%
B%
C_8%
D6E7%
RECORD_NUMBER%
THE_VALUE_I_WANT%

If the default or explicitly declared data type is INTEGER, the percent suffix (%) is not necessary.

If you assign a floating-point or decimal value to an integer variable, BASIC truncates the fractional portion of the value. It does not round to the nearest integer. For example:


B% = -5.7

BASIC assigns the value -5 to the integer variable, not -6.

A string variable is a named location that stores strings.

Following are some examples of valid string variable names:

C1$
L_6$
ABC1$
M$
F34G$
T..$
EMPLOYEE_NAME$
TARGET_RECORD$
STORAGE_SHELF_IDENTIFIER$

If the default or explicitly declared data type is STRING, the dollar suffix ($) is not necessary.

Strings have both value and length. BASIC sets all string variables to a default length of zero before program execution begins, with the exception of those variables in a COMMON, MAP, virtual array, or record definition. See the COMMON statement and the MAP statement in Chapter 3 for information about string length in COMMON and MAP areas. See the HP BASIC for OpenVMS User Manual for information about default string length in virtual arrays.

During execution, the length of a character string associated with a string variable can vary from zero (signifying a null or empty string) to 65,535 characters.


Previous Next Contents Index