Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


PRINT USING

The PRINT USING statement generates output formatted according to a format string (either numeric or string) to a terminal or a terminal-format file.

Format



Syntax Rules

  1. Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#). If you do not specify a channel, BASIC prints to the controlling terminal.
  2. Str-exp is the format string. It must contain at least one valid format field and must be followed by a separator (comma or semicolon) and at least one expression.

    Note

    It is recommended that you use compile-time constant expressions for str-exp whenever possible. When you do this, the BASIC compiler compiles the string at compilation time rather than at run time, thus improving the performance of your program.
  3. Output-list specifies the expressions to be printed.

Remarks

  1. The PRINT USING statement can print up to:
  2. A terminal or terminal-format file must be open on the specified channel or BASIC signals an error.
  3. The separator characters (comma or semicolon) in the PRINT USING statement do not control the print format as in the PRINT statement. The print format is controlled by the format string; therefore, it does not matter whether you use a comma or semicolon.
  4. Formatting Numeric Output
  5. BASIC interprets any other characters in a numeric format string as string literals.
  6. Depending on usage, the same format string characters can be combined to form one or more print fields within a format string. For example:
  7. The comma (digit separator), dollar sign (currency symbol), and decimal point (radix point) are the defaults for U.S. currency. On VMS systems, you can change the digit separator, currency symbol and radix point by assigning the logical names SYS$DIGIT_SEP, SYS$CURRENCY and SYS$RADIX_POINT. Once you make each assignment, the PRINT USING statement accesses these logical names for these symbols.
  8. For E-format notation, PRINT USING left-justifies the number in the format field and adjusts the exponent to compensate, except when printing zero. When printing zero in E-format notation, BASIC prints leading spaces, leading zeros, a decimal point, and zeros in the fractional portion if the PRINT USING string contains these formatting characters, and then the string "E+00".
  9. Zero cannot be negative. If a small negative number rounds to zero, it is represented as a positive zero.
  10. If there are reserved positions to the left of the decimal point, and the printed number is less than 1, BASIC prints one zero to the left of the decimal point and pads with spaces to the left of the zero.
  11. If there are more reserved positions to the right of the decimal point than fractional digits, BASIC prints trailing zeros in those positions.
  12. If there are fewer reserved positions to the right of the decimal point than fractional digits, BASIC rounds the number to fit the reserved positions.
  13. If a number does not fit in the specified format field, BASIC prints a percent sign warning symbol (%), followed by the number in PRINT format.
  14. Formatting String Output
  15. BASIC interprets any other characters in the format string as string literals and prints them exactly as they appear.
  16. If a comma or semicolon follows the last item in output-list:
  17. If no punctuation follows the last item in output-list:


Examples

Example 1


PRINT USING "###.###",-12.345 
PRINT USING "##.###",12.345 

Output


-12.345 
12.345 

Example 2


INPUT "Your Name";Winner$ 
       Jackpot = 10000.0 
PRINT USING "CONGRATULATIONS, 'EEEEEEEEE, YOU WON $$#####.##", Winner$, Jackpot 
END 

Output


Your Name? Hortense Corabelle 
CONGRATULATIONS, Hortense Corabelle, YOU WON $10000.00 


PROD$

The PROD$ function returns a numeric string that is the product of two numeric strings. The precision of the returned numeric string depends on the value of an integer argument.

Format



Syntax Rules

  1. Str-exp1 and str-exp2 specify the numeric strings you want to multiply. A numeric string can contain an optional minus sign (-), ASCII digits, and an optional decimal point (.).
  2. If str-exp consists of more than 60 characters, BASIC signals the error "Illegal number" (ERR=52).
  3. Int-exp specifies the numeric precision of str-exp. Table 4-4 shows examples of rounding and truncation and the values of int-exp that produce them.

Remarks

  1. The PROD$ function does not support E-format notation.
  2. Str-exp is rounded or truncated, or both, according to the value of int-exp.
  3. If int-exp is from -60 to 60, rounding and truncation occur as follows:
  4. If int-exp is from 9940 to 10,060, truncation occurs as follows:
  5. If int-exp is not from -60 to 60 or 9940 to 10,060, BASIC returns a value of zero.
  6. If you specify a floating-point expression for int-exp, BASIC truncates it to an integer of the default size.

Example


DECLARE STRING num_exp1, & 
               num_exp2, & 
               product 
num_exp1 = "34.555" 
num_exp2 = "297.676" 
product = PROD$(num_exp1, num_exp2, 1) 
PRINT product 

Output


10286.2 


PROGRAM

The PROGRAM statement allows you to identify a main program with a name other than the file name.

Format



Syntax Rules

  1. Prog-name specifies the module name of the compiled source and cannot be the same as any SUB, FUNCTION, or PICTURE name.
  2. Prog-name also defines the global entry point name for the main program.
  3. The first character of a prog-name must be an alphabetic character (A to Z). The remaining characters, if any, can be any combination of alphabetic characters, digits (0 to 9), dollar signs ($), periods (.), and underscores (_).
  4. Prog-name cannot be a quoted name.

Remarks

  1. The PROGRAM statement must be the first statement in a main program and can be preceded only by comment fields and lexical directives.
  2. If you insert the program into a text or object library or examine it using the OpenVMS Debugger, the program name you specify will be the module name used.
  3. A PROGRAM statement does not require a matching END PROGRAM statement.
  4. The PROGRAM statement is optional; BASIC allows you to specify an END PROGRAM statement and an EXIT PROGRAM statement without a matching PROGRAM statement.

Example


PROGRAM first_test 
   .
   .
   .
END PROGRAM 


PUT

The PUT statement transfers data from the record buffer to a file. PUT statements are valid on RMS sequential, relative, and indexed files. You cannot use PUT statements on terminal-format files or virtual array files.

Format



Syntax Rules

  1. Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).
  2. The RECORD clause allows you to randomly write records to a relative or sequential fixed file by specifying the record number. Num-exp must be between 1 and the maximum record number allowed for the file. BASIC does not allow you to use the RECORD clause on sequential variable, sequential stream, or indexed files.
  3. Int-exp in the COUNT clause specifies the record's size. If there is no COUNT clause, the record's size is that defined by the MAP or RECORDSIZE clause in the OPEN statement. The RECORDSIZE clause overrides the MAP clause.

Remarks

  1. For sequential access, the file associated with chnl-exp must be open with ACCESS WRITE, MODIFY, SCRATCH, or APPEND.
  2. To add records to an existing sequential file, open it with ACCESS APPEND. If you are not at the end of the file when attempting a PUT to a sequential file, BASIC signals "Not at end of file" (ERR=149).
  3. After a PUT statement executes, there is no current record pointer. The next record pointer is set as follows:
  4. When you specify a RECORD clause, BASIC evaluates num-exp and uses this value as the relative record number of the target cell.
  5. A PUT statement with no RECORD clause writes records to the file as follows:
  6. When you open a file as ORGANIZATION VIRTUAL, the file you open is a sequential fixed file with a record size that is a multiple of 512 bytes. You can then access the file with the FIND, GET, PUT, or UPDATE statements or through one or more virtual arrays. BASIC allows you to overwrite existing records in a file not containing virtual arrays and opened as ORGANIZATION VIRTUAL by using the PUT statement with a RECORD clause. All other organizations require the UPDATE statement to change an existing record. It is recommended that you also use the UPDATE statement to change existing records in VIRTUAL files that do not contain virtual arrays.
  7. If an existing record in an indexed file has a record with the same key value as the one you want to put in the file, BASIC signals the error "Duplicate key detected" (ERR=134) if you did not specify DUPLICATES for the key in the OPEN statement. If you specified DUPLICATES, RMS stores the duplicate records in a first-in/first-out sequence.
  8. The number specified in the COUNT clause determines how many bytes are transferred from the buffer to a file:

Examples

Example 1


!Sequential, Relative, Indexed, and Virtual Files 
PUT #3, COUNT 55% 

Example 2


!Relative and Virtual Files Only 
PUT #5, RECORD 133, COUNT 16% 


Previous Next Contents Index