Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


COMP%

The COMP% function compares two numeric strings and returns -1, 0, or 1, depending on the results of the comparison.

Format



Syntax Rules

Str-exp1 and str-exp2 are numeric strings with an optional minus sign (-), ASCII digits, and an optional decimal point (.).


Remarks

  1. If str-exp1 is greater than str-exp2, COMP% returns 1.
  2. If the string expressions are equal, COMP% returns 0.
  3. If str-exp1 is less than str-exp2, COMP% returns -1.
  4. The value returned by the COMP% function is an integer of the default size.
  5. The COMP% function does not support E-format notation.

Example


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 ";result 

Output


The value is -1 


CONTINUE

The CONTINUE statement causes BASIC to clear an error condition and resume execution at the statement following the statement that caused the error or at the specified target.

Format



Syntax Rules

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.


Remarks

  1. CONTINUE with no target causes BASIC to transfer control to the statement immediately following the statement that caused the error. The next remark is an exception to this rule.
  2. 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.

  3. The CONTINUE statement must be lexically inside of a handler.
  4. If you specify a CONTINUE statement within a detached handler, you cannot specify a target.

Example


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 


COS

The COS function returns the cosine of an angle in radians or degrees.

Format



Syntax Rules

None


Remarks

  1. 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.
  2. BASIC expects the argument of the COS function to be a real expression. When the argument is a real expression, BASIC returns a value of the same floating-point size. When the argument is not a real expression, BASIC converts the argument to the default floating-point size and returns a value of the default floating-point size.

Example


DECLARE SINGLE cos_value 
cos_value = 26 
PRINT COS(cos_value) 

Output


 .646919 


CTRLC

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.

Format



Syntax Rules

None


Remarks

  1. When 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.
  2. In a series of linked subprograms, setting Ctrl/C for one subprogram enables Ctrl/C trapping for all subprograms.
  3. 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.
  4. Ctrl/C trapping is asynchronous; that is, 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.
  5. 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.
  6. The CTRLC function always returns a value of zero.
  7. The function RCTRLC disables Ctrl/C trapping. See the description of the RCTRLC function for further details.

Example


WHEN ERROR USE repair_work 
Y% = CTRLC 
   .
   .
   .
END WHEN 
HANDLER repair_work 
IF (ERR=28) THEN PRINT "Interrupted by CTRLC!" 
   .
   .
   .
END HANDLER 


CVT$$

The CVT$$ function is a synonym for the EDIT$ function. See the EDIT$ function for more information.

Note

It is recommended that you use the EDIT$ function rather than the CVT$$ function for new program development.

Format



CVTxx

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.

Note

CVT functions are supported only for compatibility with BASIC-PLUS. It is recommended that you use the BASIC dynamic mapping feature or multiple MAP statements for new program development.

Format



Syntax Rules

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.


Remarks

  1. CVT$%
  2. CVT%$
  3. CVT$F
  4. CVTF$


Examples

Example 1


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) 
END 

Output


 16724 
 24948 
AT 
at 

Example 2


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 CVTF

Output


 .218256E+12 
 .466242E+31 
DESK 
desk 


DATA

The DATA statement creates a data block for the READ statement.

Format



Syntax Rules

  1. Num-lit specifies a numeric literal.
  2. Str-lit is a character string that starts and ends with double or single quotation marks. The quotation marks must match.
  3. Unq-str is a character sequence that does not start or end with double quotation marks and does not contain a comma.
  4. Commas separate data elements. If a comma is part of a data item, the entire item must be enclosed in quotation marks.

Remarks

  1. Because BASIC treats comment fields in DATA statements as part of the DATA sequence, you should not include comments.
  2. A DATA statement must be the last or the only statement on a physical line.
  3. DATA statements must end with a line terminator.
  4. When a DATA statement is continued with an ampersand (&), BASIC interprets all characters between the keyword DATA and the ampersand as part of the data. Any code that appears on a noncontinued line is considered a new statement.
  5. You cannot use the percent sign suffix for integer constants that appear in DATA statements. An attempt to do so causes BASIC to signal the error, "Data format error" (ERR=50).
  6. DATA statements are local to a program module.
  7. BASIC does not execute DATA statements. Instead, control is passed to the next executable statement.
  8. A program can have more than one DATA statement. BASIC assembles data from all DATA statements in a single program unit into a lexically ordered single data block.
  9. BASIC ignores leading and trailing blanks and tabs unless they are in a string literal.
  10. Commas are the only valid data delimiters. You must use a quoted string literal if a comma is to be part of a string.
  11. BASIC ignores DATA statements without an accompanying READ statement.
  12. BASIC signals the error "Data format error" if the DATA item does not match the data type of the variable specified in the READ statement or if a data element that is to be read into an integer variable ends with a percent sign (%). If a string data element ends with a dollar sign ($), BASIC treats the dollar sign as part of the string.

Example


10 DECLARE INTEGER A,B,C 
   READ A,B,C 
   DATA 1,2,3 
   PRINT A + B + C 

Output


 6 


DATE$

The DATE$ function returns a string containing a day, month, and year in the form dd-mmm-yy.

Format



Syntax Rules

  1. Int-exp can have up to 6 digits in the form yyyddd, where the characters yyy specify the number of years since 1970 and the characters ddd specify the day of that year. The day of year must be a value between 1 and the number of days in the specified year.
  2. You must fill all three of the d positions with digits or zeros before you can fill the y positions. For example:

Remarks

  1. If int-exp equals zero, DATE$ returns the current date.
  2. The str-var returned by the DATE$ function consists of nine characters and expresses the day, month, and year in the form dd-mmm-yy.
  3. If you specify an invalid date, such as day 385, results are unpredictable.
  4. If you specify a floating-point expression for int-exp, BASIC truncates it to an integer of the default size.

Example


DECLARE STRING todays_date 
todays_date = DATE$(0) 
PRINT todays_date 

Output


09-Oct-99 

The DATE4$ function is strongly recommended as replacement for the DATE$ function to avoid problems in the year 2000 and beyond. It functions the same as the DATE$ function except that the year portion of the result string contains two more digits indicating the century. For example:


PRINT 32150, DATE$ (32150), DATE4$ (32150) 

This produces the following output:


32150   30-May-02   30-May-2002 


DATE4$

The DATE4$ function returns a string containing a day, month, and year in the form dd-mmm-yyyy.

Format



Syntax Rules

  1. Int-exp can have up to 6 digits in the form yyyddd, where the characters yyy specify the number of years since 1970 and the characters ddd specify the day of that year. The day of year must be a value between 1 and the number of days in the specified year.
  2. You must fill all three of the d positions with digits or zeros before you can fill the y positions.

Remarks

The DATE4$ function is strongly recommended as replacement for the DATE$ function to avoid problems in the year 2000 and beyond. It functions the same as the DATE$ function except that the year portion of the result string contains two more digits indicating the century. For example:


PRINT 32150, DATE$ (32150), DATE4$ (32150) 

Produces the following output:


32150   30-May-02   30-May-2002 

See the description of the DATE$ function for more information.


DECIMAL

The DECIMAL function converts a numeric expression or numeric string to the DECIMAL data type.

Format



Syntax Rules

  1. Int-const1 specifies the total number of digits (the precision) and int-const2 specifies the number of digits to the right of the decimal point (the scale). If you do not specify these values, BASIC uses the d (digits) and s (scale) defaults for the DECIMAL data type.
  2. Int-const1 and int-const2 must be positive integers from 1 to 31. Int-const2 cannot exceed the value of int-const1.
  3. Exp can be either numeric or numeric string. If a numeric string, it can contain the ASCII digits 0 to 9, a plus sign (+), a minus sign (-), and a period (.).

Remarks

  1. If exp is a string, BASIC ignores leading and trailing spaces and tabs.
  2. The DECIMAL function returns a zero when a string argument contains only spaces and tabs, or when it is null.


Example


DECLARE STRING CONSTANT format_string = "##.###" 
DECLARE STRING num_value, DECIMAL(5,3) B 
INPUT "Enter a numeric value";num_value 
B = DECIMAL(num_value,5,3) 
PRINT USING format_string, B 

Output


Enter a numeric value? 6 
 6.000 


DECLARE

The DECLARE statement explicitly assigns a name and a data type to a variable, an entire array, a function, or a constant.

Format



Syntax Rules

  1. Data-type can be any 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.
  2. Variables
  3. DEF Functions
  4. Named Constants

Remarks

  1. The DECLARE statement is not executable.
  2. The DECLARE statement must lexically precede any reference to the variables, functions, or constants named in it.
  3. To declare a virtual or run-time array, use the DIMENSION statement.
  4. Variables
  5. DEF Functions
  6. Named Constants