CONTENTS Title Page Copyright Page Preface Part I Developing BASIC Programs on OpenVMS Systems 1 Overview of the BASIC Language 2 Developing VAX BASIC Programs in the BASIC Environment 2.1 Entering the Environment 2.2 Creating and Running Programs 2.3 Immediate Mode 2.4 Debugging in Immediate Mode 2.5 Compiler Commands 2.5.1 Entering Comments 2.5.2 Entering DCL Commands 2.5.2.1 APPEND Command 2.5.2.2 ASSIGN Command 2.5.2.3 COMPILE Command 2.5.2.4 CONTINUE Command 2.5.2.5 DELETE Command 2.5.2.6 EDIT Command 2.5.3 EXIT Command 2.5.4 HELP Command 2.5.4.1 IDENTIFY Command 2.5.4.2 LIST and LISTNH Commands 2.5.4.3 LOAD Command 2.5.4.4 LOCK Command 2.5.4.5 NEW Command 2.5.4.6 OLD Command 2.5.4.7 RENAME Command 2.5.4.8 REPLACE Command 2.5.4.9 RESEQUENCE Command 2.5.4.10 RUN and RUNNH Commands 2.5.4.11 SAVE Command 2.5.4.12 SCALE Command 2.5.4.13 SCRATCH Command 2.5.4.14 SEQUENCE Command 2.5.4.15 SET Command 2.5.4.16 SHOW Command 2.5.4.17 UNSAVE Command 3 Developing BASIC Programs at the DCL Command Level 3.1 Compiling a BASIC Program 3.1.1 BASIC Command 3.1.2 BASIC Command Qualifiers 3.1.3 Compiler Listings 3.2 Linking a BASIC Program 3.2.1 LINK Command 3.2.2 LINK Command Qualifiers 3.2.3 Linker Input Files 3.2.4 Linker Output Files 3.2.5 Using an Object Module Library 3.2.6 Linker Error Messages 3.3 Running a BASIC Program 4 Using the OpenVMS Debugger with BASIC 4.1 Overview of the Debugger 4.2 Compiling and Linking to Prepare for Debugging 4.3 Viewing Your Source Code 4.3.1 Noscreen Mode 4.3.2 Screen Mode 4.4 Controlling and Monitoring Program Execution 4.4.1 Starting and Resuming Program Execution 4.4.2 Determining the Current Location of the Program Counter 4.4.3 Suspending Program Execution 4.4.4 Tracing Program Execution 4.4.5 Monitoring Changes in Variables 4.5 Examining and Manipulating Data 4.5.1 Displaying the Values of Variables 4.5.2 Changing the Values of Variables 4.5.3 Evaluating Expressions 4.6 Stepping Into BASIC Routines 4.6.1 Controlling Symbol References 4.7 A Sample Debugging Session Part II BASIC Programming Concepts 5 BASIC Concepts and Elements 5.1 Line Numbers 5.1.1 Programs with Line Numbers 5.1.2 Programs without Line Numbers 5.1.3 Labels 5.1.4 Continuation of Long Program Statements 5.2 Identifying Program Units 5.3 BASIC Character Set 5.4 Program Documentation 5.5 Declarations and Data Types 5.5.1 Implicit Data Typing 5.5.2 Explicit Data Typing 5.6 Constants 5.7 Variables 5.7.1 Floating-Point Variables 5.7.2 Integer Variables 5.7.3 Packed Decimal Variables 5.7.4 String Variables 5.7.5 Subscripted Variables 5.7.6 Initialization of Variables 5.8 Keywords and Reserved Words 5.9 Operands, Operators, and Expressions 5.10 Assignment Statements 6 Simple Input and Output 6.1 Program Input 6.1.1 Providing Input Interactively 6.1.1.1 INPUT Statement 6.1.1.2 INPUT LINE and LINPUT Statements 6.1.1.3 Enabling and Disabling the Question Mark Prompt 6.1.2 Providing Input from the Source Program 6.1.2.1 READ and DATA Statements 6.1.2.2 RESTORE Statement 6.2 Program Output 6.2.1 Print Zones-The Comma and the Semicolon 6.2.2 Output Format for Numbers and Strings 6.3 Terminal-Format Files 6.3.1 Opening and Closing a Terminal-Format File 6.3.2 Writing Records to a Terminal-Format File 7 Arrays 7.1 Overview of Arrays 7.2 Creating Arrays Explicitly 7.2.1 Creating Arrays with the DECLARE Statement 7.2.2 Creating Arrays with the DIM Statement 7.2.2.1 Declarative DIM Statements 7.2.2.2 Executable DIM Statements 7.2.3 Creating Arrays with the COMMON Statement 7.2.4 Creating Arrays with the MAP Statement 7.3 Creating Arrays Implicitly 7.4 Determining the Bounds of an Array 7.5 Assigning and Displaying Array Values 7.5.1 Assigning Values with the LET Statement 7.5.2 Listing Array Elements with the PRINT Statement 7.6 Using MAT Statements 7.6.1 MAT Statement 7.6.2 MAT READ Statement 7.6.3 MAT INPUT [#] Statement 7.6.4 MAT LINPUT [#] Statement 7.6.5 MAT PRINT [#] Statement 7.6.6 Matrix I/O Functions (NUM and NUM2) 7.7 Matrix Operators 7.7.1 Arithmetic Matrix Operations 7.7.1.1 Assignment 7.7.1.2 Addition and Subtraction 7.7.1.3 Multiplication 7.7.2 Matrix Functions 7.7.2.1 TRN Function 7.7.2.2 INV Function 7.7.2.3 DET Function 8 Data Definition 8.1 Declarative Statements 8.2 Data Types 8.3 Setting the Default Data Type and Size 8.4 Declaring Variables 8.5 Declaring Named Constants 8.6 Operations with Multiple Data Types 8.7 Allocating Static Storage 8.7.1 COMMON Statement 8.7.2 MAP Statement 8.7.2.1 Single Maps 8.7.2.2 Multiple Maps 8.7.3 FILL Items 8.7.4 Using COMMON and MAP Statements in Subprograms 8.8 Dynamic Mapping 9 Creating and Using Data Structures 9.1 RECORD Statement 9.1.1 Grouping RECORD Components 9.1.2 RECORD Variants 9.1.3 Accessing RECORD Components 10 Program Control 10.1 Statement Modifiers 10.1.1 IF Modifier 10.1.2 UNLESS Modifier 10.1.3 FOR Modifier 10.1.4 UNTIL Modifier 10.1.5 WHILE Modifier 10.1.6 Nesting Modifiers 10.2 Loops 10.2.1 FOR...NEXT Loops 10.2.2 WHILE...NEXT Loops 10.2.3 UNTIL...NEXT Loops 10.2.4 Nesting Loops 10.3 Unconditional Branching (GOTO Statement) 10.4 Conditional Branching 10.4.1 ON...GOTO...OTHERWISE Statement 10.4.2 IF...THEN...ELSE Statement 10.4.3 SELECT...CASE Statement 10.5 EXIT and ITERATE Statements 10.6 Executing Local Subroutines 10.6.1 GOSUB and RETURN Statements 10.6.2 ON...GOSUB...OTHERWISE Statement 10.7 Suspending and Halting Program Execution 10.7.1 SLEEP Statement 10.7.2 WAIT Statement 10.7.3 STOP Statement 10.7.4 END Statement 11 Functions 11.1 Built-In Functions 11.1.1 Numeric Functions 11.1.1.1 ABS Function 11.1.1.2 INT and FIX Functions 11.1.1.3 SIN, COS, and TAN Functions 11.1.1.4 LOG10 Function 11.1.1.5 EXP Function 11.1.1.6 RND Function 11.1.2 Data Conversion Functions 11.1.2.1 ASCII Function 11.1.2.2 CHR$ Function 11.1.3 String Numeric Functions 11.1.3.1 FORMAT$ Function 11.1.3.2 NUM$ and NUM1$ Functions 11.1.3.3 VAL% and VAL Functions 11.1.4 String Arithmetic Functions 11.1.4.1 SUM$ and DIF$ Functions 11.1.4.2 QUO$, PLACE$, and PROD$ Functions 11.1.5 Date and Time Functions 11.1.5.1 DATE$ Function 11.1.5.2 TIME$ Function 11.1.5.3 TIME Function 11.1.6 Terminal Control Functions 11.1.6.1 CTRLC and RCTRLC Functions 11.1.6.2 ECHO and NOECHO Functions 11.1.6.3 INKEY$ Function 11.2 User-Defined Functions 11.2.1 Single-Line DEF Functions 11.2.2 Multiline DEF Functions 12 String Handling 12.1 Overview of Strings 12.2 Using Dynamic Strings 12.3 Using Fixed-Length Strings 12.4 Using String Virtual Arrays 12.5 Assigning String Data 12.5.1 LET Statement 12.5.2 LSET Statement 12.5.3 RSET Statement 12.5.4 MID$ Assignment Statement 12.6 Manipulating String Data with String Functions 12.6.1 LEN Function 12.6.2 POS Function 12.6.3 SEG$ Function 12.6.4 MID$ Function 12.6.5 STRING$ Function 12.6.6 SPACE$ Function 12.6.7 TRM$ Function 12.6.8 EDIT$ Function 12.7 Manipulating String Data with Multiple Maps 13 Program Segmentation 13.1 BASIC Subprograms 13.1.1 SUB Subprograms 13.1.2 FUNCTION Subprograms 13.2 Declaring Subprograms and Parameters 13.3 Compiling Subprograms 13.4 Invoking Subprograms 13.4.1 Invoking SUB Subprograms 13.4.2 Invoking FUNCTION Subprograms 13.5 Returning Program Status 14 File Input and Output 14.1 Record Formats 14.1.1 Fixed-Length Records 14.1.2 Variable-Length Records 14.1.3 Stream Records 14.2 File Organizations 14.2.1 Terminal-Format Files 14.2.2 Sequential Files 14.2.3 Relative Files 14.2.4 Indexed Files 14.2.5 Virtual Files 14.3 Record Access and Record Context 14.4 I/O and Record Buffers 14.5 Accessing the Contents of a Record 14.5.1 MAP Statement 14.5.2 MAP DYNAMIC and REMAP Statements 14.5.3 MOVE Statement 14.6 File and Record Operations 14.6.1 Opening Files 14.6.2 Creating Virtual Array Files 14.6.3 Locating Records 14.6.4 Reading Records 14.6.5 Writing Records 14.6.6 Deleting Records 14.6.7 Updating Records 14.6.8 Controlling Record Access 14.6.9 Gaining Access to Locked Records 14.6.10 Accessing Records by Record File Address 14.6.11 Transferring Data to Terminal-Format Files 14.6.12 Resetting the File Position 14.6.13 Truncating Files 14.6.14 Renaming Files 14.6.15 Closing Files and Ending I/O 14.6.16 Deleting Files 14.7 File-Related Functions 14.7.1 FSP$ Function 14.7.2 RECOUNT Function 14.7.3 STATUS, VMSSTATUS, and RMSSTATUS Functions 14.8 OPEN Statement Options 14.8.1 BUCKETSIZE Clause 14.8.2 BUFFER Clause 14.8.3 CONNECT Clause 14.8.4 CONTIGUOUS Clause 14.8.5 DEFAULTNAME Clause 14.8.6 EXTENDSIZE Clause 14.8.7 FILESIZE Clause 14.8.8 NOSPAN Clause 14.8.9 RECORDTYPE Clause 14.8.10 TEMPORARY Clause 14.8.11 USEROPEN Clause 14.8.12 WINDOWSIZE Clause 15 Formatting Output with the PRINT USING Statement 15.1 Overview of the PRINT USING Statement 15.2 Using Format Strings 15.3 Printing Numbers 15.3.1 Specifying the Number of Digits 15.3.2 Specifying Decimal Point Location 15.3.3 Printing Numbers with Special Symbols 15.3.3.1 Commas 15.3.3.2 Asterisk-Fill Fields 15.3.3.3 Currency Symbols 15.3.3.4 Negative Fields 15.3.3.5 E (Exponential) Format 15.3.3.6 Leading Zeros 15.3.3.7 Blank-If-Zero Fields 15.3.3.8 Debits and Credits 15.4 Printing Strings 15.4.1 Left-Justified Format 15.4.2 Right-Justified Format 15.4.3 Centered Fields 15.4.4 Extended Fields 15.5 PRINT USING Statement Error Conditions 16 Handling Run-Time Errors 16.1 Default Error Handling 16.2 User-Supplied Error Handlers 16.2.1 Protected Regions 16.2.2 Handlers 16.2.3 Exiting from Handlers 16.2.3.1 RETRY Statement 16.2.3.2 CONTINUE Statement 16.2.3.3 EXIT HANDLER Statement 16.2.4 Selecting the Severity of Errors to Handle 16.2.5 Identifying Errors 16.2.5.1 Determining the Error Number (ERR) 16.2.5.2 Determining the Error Line Number (ERL) 16.2.5.3 Determining Where the Error Occurred (ERN$) 16.2.5.4 Determining the Error Message Text (ERT$) 16.2.5.5 Determining OpenVMS Error Information 16.2.5.6 Determining RMS Error Information 16.2.6 Ctrl/C Trapping 16.2.7 Handling Errors in Multiple-Unit Programs 16.2.8 Forcing Errors 16.3 Using the ON ERROR Statements 17 Compiler Directives 17.1 Overview of Compiler Directives 17.2 Controlling the Compilation Listing 17.2.1 %TITLE and %SBTTL Directives 17.2.2 %IDENT Directive 17.2.3 %PAGE Directive 17.2.4 %LIST and %NOLIST Directives 17.2.5 %CROSS and %NOCROSS Directives 17.3 Accessing External Source Files 17.4 Controlling Compilation 17.4.1 %LET Directive 17.4.2 %VARIANT Directive 17.4.3 %ABORT Directive 17.4.4 %PRINT Directive 17.4.5 %IF-%THEN-%ELSE-%END %IF Directive 17.5 Record Dependency Relationships in CDD/Repository 18 Data Representation 18.1 Integer Format 18.1.1 Byte-Length Integer Format 18.1.2 Word-Length Integer Format 18.1.3 Longword Integer Format 18.2 Real Number Format 18.2.1 SINGLE Floating-Point Number Format (F_floating) 18.2.2 DOUBLE Floating-Point Number Format (D_floating) 18.2.3 GFLOAT Floating-Point Number Format (G_floating) 18.2.4 HFLOAT Floating-Point Number Format (H_floating)-VAX BASIC Only 18.3 Packed Decimal Number Format 18.4 String and Array Descriptor Format 18.4.1 Fixed-Length String Descriptor Format 18.4.2 Dynamic String Descriptor Format 18.5 Array Descriptors 18.6 Decimal Scalar String Descriptor (Packed Decimal String Descriptor) Part III Using BASIC Features on OpenVMS Systems 19 Advanced File Input and Output 19.1 RMS I/O to Magnetic Tape 19.1.1 Allocating and Mounting a Tape 19.1.2 Opening a Tape File for Output 19.1.3 Opening a Tape File for Input 19.1.4 Positioning a Tape 19.1.5 Writing Records to a File 19.1.6 Reading Records from a File 19.1.7 Controlling Tape Output Format 19.1.8 Rewinding a Tape 19.1.9 Closing a File 19.2 Device-Specific I/O 19.2.1 Device-Specific I/O to Unit Record Devices 19.2.2 Device-Specific I/O to Magnetic Tape Devices 19.2.2.1 Allocating and Mounting a Tape 19.2.2.2 Opening a Tape File for Output 19.2.2.3 Opening a Tape File for Input 19.2.2.4 Writing Records to a File 19.2.2.5 Reading Records from a File 19.2.2.6 Rewinding a Tape 19.2.2.7 Closing a Tape 19.2.3 Device-Specific I/O to Disks 19.2.3.1 Assigning and Mounting a Disk 19.2.3.2 Opening a Disk File for Output 19.2.3.3 Opening a Disk File for Input 19.2.3.4 Writing Records to a Disk File 19.2.3.5 Reading Records from a Disk File 19.3 I/O to Mailboxes 19.4 Network I/O 19.4.1 Remote File Access 19.4.2 Task-to-Task Communication 19.4.3 Accessing a VAX Rdb/VMS Database 20 Using BASIC in the Common Language Environment 20.1 Specifying Parameter-Passing Mechanisms 20.1.1 Passing Parameters by Reference 20.1.2 Passing Parameters by Descriptor 20.1.3 Passing Parameters by Value 20.1.4 BASIC Default Parameter-Passing Mechanisms 20.1.5 Creating Local Copies 20.2 Calling External Routines 20.2.1 Determining the Type of Call 20.2.2 Declaring an External Routine and Its Arguments 20.2.3 Calling the Routine 20.3 Calling BASIC Subprograms from Other Languages 20.4 Calling System Routines 20.4.1 OpenVMS Run-Time Library Routines 20.4.2 System Service Routines 20.4.3 System Routine Arguments 20.4.4 Including Symbolic Definitions 20.4.5 Condition Values 20.5 Examples of Calling System Routines 20.6 The OpenVMS Calling Standard 20.7 Additional Information 21 Libraries and Shareable Images 21.1 Overview of Libraries 21.2 System-Supplied Libraries 21.3 Creating User-Supplied Object Module Libraries 21.3.1 Accessing User-Supplied Object Module Libraries in the BASIC Environment 21.3.2 Accessing User-Supplied Object Module Libraries at DCL Level 21.4 Shareable Images 21.4.1 Accessing Shareable Images in the BASIC Environment 21.4.2 Accessing Shareable Images at DCL Level 22 Using CDD/Repository with BASIC 22.1 Overview of CDD/Repository 22.2 CDD/Repository Concepts 22.2.1 Dictionary Formats 22.2.2 Dictionary Path Names 22.2.3 Dictionary Entities 22.2.4 Dictionary Relationships 22.2.5 Extracting CDD/Repository Data Definitions 22.3 Using CDD/Repository with BASIC 22.3.1 /DEPENDENCY_DATA Qualifier 22.3.2 Creating Relationships with Included Record Definitions 22.4 Creating Relationships for Referenced Dictionary Entities 22.5 Specifying a CDD History List Entry 22.6 CDD/Repository Arrays 22.7 CDD/Repository Variants 22.8 NAME FOR BASIC Clause 22.9 CDD/Repository Data Types 22.9.1 Character String Data Types 22.9.2 Integer Data Types 22.9.3 Floating-Point Data Types 22.9.4 Decimal String Data Types 22.9.5 Other Data Types A Compile-Time Error Messages A.1 Compile-Time Errors B Run-Time Error Messages B.1 BASIC Run-Time Errors By Mnemonic B.2 BASIC Run-time Errors By Number B.3 Errors Not Generated By BASIC C Optional Programming Productivity Tools C.1 DEC Language-Sensitive Editor (LSE) and Source Code Analyzer (SCA) C.1.1 Preparing an SCA Library C.1.2 Compiling from within LSE C.1.3 BASIC Support for LSE and SCA Features C.1.3.1 Programming Language Placeholders and Tokens C.1.3.2 Placeholder and Design Comment Processing C.2 CDD/Repository C.3 DEC Database Management System (DEC DBMS) C.4 VAX DEC/Test Manager C.5 VAX DEC/Code Management System (CMS)