[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP BASIC for OpenVMS
|
Previous | Contents | Index |
The CHR$ function returns a 1-character string that corresponds to the ASCII value you specify.
None
- CHR$ returns the character whose ASCII value equals int-exp. If int-exp is greater than 255, HP BASIC treats it as modulo 256. For example, CHR$(325) is the same as CHR$(69).
- If you specify a floating-point expression for int-exp, HP BASIC truncates it to an integer of the default size.
DECLARE INTEGER num_exp INPUT "Enter the ASCII value you wish to be converted";num_exp PRINT "The equivalent character is ";CHR$(num_exp)Output
Enter the ASCII value you wish to be converted? 89 The equivalent character is Y
The CLOSE statement ends I/O processing to a device or file on the specified channel.
Chnl-exp is a numeric expression that specifies a channel number associated with a file. It can be preceded by an optional number sign (#).
- HP BASIC writes the contents of any active output buffers to the file or device before it closes that file or device.
- Channel #0 (the controlling terminal) cannot be closed. An attempt to do so has no effect.
- If you close a magnetic tape file that is open for output, HP BASIC writes an end-of-file on the magnetic tape.
- If you try to close a channel that is not currently open, HP BASIC does not signal an error and the CLOSE statement has no effect.
OPEN "COURSE_REC.DAT" FOR INPUT AS #2 INPUT #2, course_nam, course_num, course_desc, course_instr . . . CLOSE #2In this example, COURSE_REC.DAT is opened for input. After you have retrieved all of the required information, the file is closed.
The COMMON statement defines a named, shared storage area called a COMMON block or program section (PSECT). HP BASIC program modules can access the values stored in the COMMON block by specifying a COMMON block with the same name.
- A COMMON block can have the same name as a program variable.
- A COMMON block and a map in the same program module cannot have the same name.
- Com-name is optional. If you specify a com-name, it must be in parentheses. If you do not specify a com-name, the default is $BLANK.
- Com-name can be from 1 to 31 characters. The first character of the name 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 (_).
- Data-type can be any HP BASIC data type keyword or a data type defined by a RECORD statement. Data type keywords, size, range, and precision are listed in Table 1-2.
- When you specify a data type, all following com-items, including FILL items, are of that data type until you specify a new data type.
- If you do not specify any data type, com-items without a suffix character (% or $) take the current default data type and size.
- Variable names, array names, and FILL items following a data type other than STRING cannot end with a dollar sign. Likewise, names and FILL items following a data type other than BYTE, WORD, LONG, QUAD, or INTEGER cannot end with a percent sign.
- Com-item declares the name and format of the data to be stored.
- Num-unsubs-var and num-array-name specify a numeric variable or a numeric array.
- Record-var specifies a record instance.
- Str-unsubs-var and str-array-name specify a fixed-length string variable or array. You can specify the number of bytes to be reserved for the variable with the =int-const clause. The default string length is 16.
- When you declare an array, HP BASIC allows you to specify both lower and upper bounds. The upper bounds is required; the lower bounds is optional.
- Int-const1 specifies the lower bounds of the array.
- Int-const2 specifies the upper bounds of the array and, when accompanied by int-const1, must be preceded by the keyword TO.
- Int-const1 must be less than or equal to int-const2.
- If you do not specify int-const1, HP BASIC uses zero as the default lower bounds.
- Int-const1 and int-const2 can be any combination of negative and/or positive values.
- The FILL, FILL%, and FILL$ keywords allow you to reserve parts of the record buffer within or between data elements and to define the format of the storage. Rep-cnt specifies the number of FILL items to be reserved. The =int-const clause allows you to specify the number of bytes to be reserved for string FILL items. Table 3-1 describes FILL item format and storage allocation.
- In the applicable formats of FILL, (rep-cnt) represents a repeat count, not an array subscript. FILL (n) represents n elements, not n + 1.
Table 3-1 FILL Item Formats and Storage Allocations FILL Format Storage Allocation FILL Allocates storage for one element of the default data type unless preceded by a data-type. The number of bytes allocated depends on the default or the specified data type. FILL( rep-cnt) Allocates storage for the number of the default data type elements specified by rep-cnt unless preceded by a data type. The number of bytes allocated for each element depends on the default floating-point data size or the specified data type. FILL% Allocates storage for one integer element. The number of bytes allocated depends on the default integer size. FILL%( rep-cnt) Allocates storage for the number of integer elements specified by rep-cnt. The number of bytes allocated for each element depends on the default integer size. FILL$ Allocates 16 bytes of storage for a string element. FILL$( rep-cnt) Allocates 16 bytes of storage for the number of string elements specified by rep-cnt. FILL$= int-const Allocates the number of bytes of storage specified by int-const for a string element. FILL$( rep-cnt)= int-const Allocates the number of bytes of storage specified by int-const for the number of string elements specified by rep-cnt.
- Variables in a COMMON area are not initialized by HP BASIC.
- HP BASIC does not execute COMMON statements. The COMMON statement allocates and defines the data storage area at compilation time.
- When you link your program, the size of the COMMON area is the size of the largest COMMON area with that name. HP BASIC concatenates COMMON statements with the same com-name within a single program module into a single PSECT. The total space allocated is the sum of the space allocated in the concatenated COMMON statements.
If you specify the same com-name in several program modules, the size of the PSECT will be determined by the program module that has the greatest amount of space allocated in the concatenated COMMON statements.- The COMMON statement must lexically precede any reference to variables declared in it.
- A COMMON area can be accessed by more than one program module, as long as you define the com-name in each module that references the COMMON area.
- A COMMON area and a MAP area with the same name specify the same storage area and are not allowed in the same program module. However, a COMMON in one module can reference the storage declared by a MAP or COMMON in another module.
- Variable names in a COMMON statement in one program module need not match those in another program module.
- Variables and arrays declared in a COMMON statement cannot be declared elsewhere in the program by any other declarative statements.
- The data type specified for com-items or the default data type and size determines the amount of storage reserved in a COMMON block. See Table 1-2.
COMMON (sales_rec) DECIMAL net_sales (1965 TO 1975), & STRING row = 2, & report_name = 24, & DOUBLE FILL, & LONG part_bins
The COMP% function compares two numeric strings and returns --1, 0, or 1, depending on the results of the comparison.
Str-exp1 and str-exp2 are numeric strings with an optional minus sign (--), ASCII digits, and an optional decimal point (.).
- If str-exp1 is greater than str-exp2, COMP% returns 1.
- If the string expressions are equal, COMP% returns 0.
- If str-exp1 is less than str-exp2, COMP% returns --1.
- The value returned by the COMP% function is an integer of the default size.
- The COMP% function does not support E-format notation.
DECLARE STRING num_string, old_num_string, & INTEGER result num_string = "-24.5" old_num_string = "33" result = COMP%(num_string, old_num_string) PRINT "The value is ";resultOutput
The value is -1
The CONTINUE statement causes HP BASIC to clear an error condition and resume execution at the statement following the statement that caused the error or at the specified target.
If you specify a target, it must be a label or line number that appears either inside the associated protected region, inside a WHEN block protected region that surrounds the current protected region, or in an unprotected region of code.
- CONTINUE with no target causes HP BASIC to transfer control to the statement immediately following the statement that caused the error. The next remark is an exception to this rule.
- If an error occurs on a FOR, NEXT, WHILE, UNTIL, SELECT or CASE statement, control is transferred to the statement immediately following the corresponding NEXT or END SELECT statement, as in the following code:
10 WHEN ERROR IN A=10 B=1 20 FOR I=A TO B STEP 2 30 GET #1 40 C=1 NEXT I 50 C=0 USE . . . CONTINUE END WHEN
If an error occurs on line 20, the CONTINUE statement transfers control to line 50. If an error occurs on line 30, program control resumes at line 40.- The CONTINUE statement must be lexically inside of a handler.
- If you specify a CONTINUE statement within a detached handler, you cannot specify a target.
WHEN ERROR USE err_handler . . . END WHEN . . . HANDLER err_handler SELECT ERR CASE = 50 PRINT "Insufficient data" CONTINUE CASE ELSE EXIT HANDLER END SELECT END HANDLER
The COS function returns the cosine of an angle in radians or degrees.
None
- The returned value is from --1 to 1. The parameter value is expressed in either radians or degrees depending on which angle clause you choose with the OPTION statement.
- HP BASIC expects the argument of the COS function to be a real expression. When the argument is a real expression, HP BASIC returns a value of the same floating-point size. When the argument is not a real expression, HP BASIC converts the argument to the default floating-point size and returns a value of the default floating-point size.
DECLARE SINGLE cos_value cos_value = 26 PRINT COS(cos_value)Output
.646919
The CTRLC function enables Ctrl/C trapping. When Ctrl/C trapping is enabled, a Ctrl/C typed at the terminal causes control to be transferred to the error handler currently in effect.
None
- When HP BASIC encounters a Ctrl/C, control passes to the error handler currently in effect. If there is no error handler in a program, the program aborts.
- In a series of linked subprograms, setting Ctrl/C for one subprogram enables Ctrl/C trapping for all subprograms.
- When you trap a Ctrl/C with an error handler, your program may be in an inconsistent state; therefore, you should handle the Ctrl/C error and exit the program as quickly as possible.
- Ctrl/C trapping is asynchronous; that is, HP BASIC suspends execution and signals "Programmable ^C trap" (ERR=28) as soon as it detects a Ctrl/C. Consequently, a statement can be interrupted while it is executing. A statement so interrupted may be only partially executed and variables may be left in an undefined state.
- HP BASIC can trap more than one Ctrl/C error in a program as long as the error does not occur while the error handler is executing. If a second Ctrl/C is detected while the error handler is processing the first Ctrl/C, the program aborts.
- The CTRLC function always returns a value of zero.
- The function RCTRLC disables Ctrl/C trapping. See the description of the RCTRLC function for further details.
WHEN ERROR USE repair_work Y% = CTRLC . . . END WHEN HANDLER repair_work IF (ERR=28) THEN PRINT "Interrupted by CTRLC!" . . . END HANDLER
The CVT$$ function is a synonym for the EDIT$ function. See the EDIT$ function for more information.
It is recommended that you use the EDIT$ function rather than the CVT$$ function for new program development. |
The CVT$% function maps the first two characters of a string into a 16-bit integer. The CVT%$ function translates a 16-bit integer into a 2-character string. The CVT$F function maps a 4- or 8-character string into a floating-point variable. The CVTF$ function translates a floating-point number into a 4- or 8-byte character string. The number of characters translated depends on whether the floating-point variable is single- or double-precision.
CVT functions are supported only for compatibility with BASIC-PLUS. It is recommended that you use the HP BASIC dynamic mapping feature or multiple MAP statements for new program development. |
real-var = CVT$F (str-var)
str-var = CVT%$ (int-var)
str-var = CVTF$ (real-var)
CVT functions reverse the order of the bytes when moving them to or from a string. Therefore, you can mix MAP and MOVE statements, but you cannot use FIELD and CVT functions on a file if you also plan to use MAP or MOVE statements.
- CVT$%
- If the CVT$% str-var has fewer than two characters, HP BASIC pads the string with nulls.
- If the default data type is LONG, only 2 bytes of data are extracted from str-var; the high-order byte is sign-extended into a longword.
- The value returned by the CVT$% function is an integer of the default size.
- CVT%$
- Only 2 bytes of data are inserted into str-var.
- If you specify a floating-point variable for int-var, HP BASIC truncates it to an integer of the default size. If the default size is BYTE and the value of int-var exceeds 127, HP BASIC signals an error.
- CVT$F
- CVT$F maps four characters when the program is compiled with /SINGLE and eight characters when the program is compiled with /DOUBLE.
- If str-var has fewer than four or eight characters, HP BASIC pads the string with nulls.
- The real-var returned by the CVT$F function is the default floating-point size. If the default size is not SINGLE or DOUBLE, HP BASIC signals the error "Floating CVT valid only for SINGLE or DOUBLE."
- CVTF$
- The CVTF$ function maps single-precision numbers to a 4-character string and double-precision numbers to an 8-character string.
- HP BASIC expects the argument of the CVTF$ function to be a real expression. When the argument is a real expression, HP BASIC returns a value of the same floating-point size. When the argument is not a real expression, HP BASIC converts the argument to the default floating-point size and returns a value of the default floating-point size. If the default floating-point size is not SINGLE or DOUBLE, HP BASIC signals the error "Floating CVT valid only for SINGLE or DOUBLE."
DECLARE STRING test_string, another_string DECLARE LONG first_number, next_number test_string = "AT" PRINT CVT$%(test_string) another_string = "at" PRINT CVT$%(another_string) first_number = 16724 PRINT CVT%$(first_number) next_number = 24948 PRINT CVT%$(next_number) ENDOutput
16724 24948 AT at
DECLARE STRING test_string, another_string DECLARE SINGLE first_num, second_num test_string = "DESK" first_num = CVT$F(test_string) PRINT first_num another_string = "desk" second_num = CVT$F(another_string) PRINT second_num PRINT CVTF$(first_num) PRINT CVTF$(second_num) END
$ BASIC/SINGLE CVTF $ LINK CVTF $ RUN CVTFOutput
.218256E+12 .466242E+31 DESK desk
Previous | Next | Contents | Index |