HTBasic Help
×
Menu
Index

OUTPUT

Outputs items to a specified destination.
 
 OUTPUT dest [USING image] [; items [{,|;}] [END] ]
 
Usage:
OUTPUT @Test;Sarray(*)
OUTPUT @Sequence,4 USING SpecA;Part(3)
OUTPUT 10 USING "6A";V$[2;6]
OUTPUT @Printer;Order;SSN;Work$,END
 
Example:           OUTPUT.BAS
 
Description:
Outputs (writes) numeric data, array elements or character strings to the specified destination.
 
Unless USING  is specified, numeric items are output in standard numeric format. If the absolute value is in the range 1E-4 to 1E+6, it is rounded to twelve digits and output in floating point form. Otherwise the number is output in scientific notation.
 
Full arrays are output in row major order, using the full array specifier, "(*)". Each element is an item and is separated by a comma or semicolon if one follows the array name.
 

Destinations

File.  An ASCII, BDAT or regular file may be used as the destination. The file must have been ASSIGNed to an I/O path. The ASSIGN statement determines the attributes to be used. With FORMAT ON, BDAT and regular files are written as ASCII characters. With FORMAT OFF, BDAT and regular files are written in internal format (explained below). An ASCII file is always written as ASCII characters. All files may be accessed serially and additionally, BDAT and regular files may be accessed randomly by including a record number.
 
String.  A string may be used as the destination. OUTPUT begins at the beginning of the string and writes it serially.
 
Device.  A device-selector or I/O path may be used to OUTPUT items to a device. The default system attributes are used with a device-selector. The ASSIGN statement determines the attributes used with an I/O path.
 
If the device selector is one, then the destination is the CRT. If the device selector is two, then the destination is the keyboard. This can be used to enter the keyboard function key sequences into the keyboard buffer. Each function sequence is two bytes, a CHR$(255) followed by the function specifier.
Buffer.  A buffer assigned to an I/O path may be used as the destination. The buffer fill pointer points to the buffer location to be written next and is updated as data is OUTPUT. If the empty pointer is encountered, an error is generated.
 

FORMAT

If the FORMAT ON attribute is specified in the ASSIGN statement, the output is sent in ASCII format and the punctuation following each item affects the output. A semicolon causes an item to be sent with nothing following it, a comma causes a string item to be sent with a CR/LF following it and a numeric item to be sent with a comma following it. If no punctuation follows the last OUTPUT item, the EOL sequence follows it and if punctuation follows the last OUTPUT item, the EOL sequence is not output.
 
A complex number is output in rectangular form, real part first, then a comma and finally, the imaginary part. If a semicolon follows the complex item then the comma is not output.
 
If the FORMAT OFF attribute is specified in the ASSIGN statement the output is sent in internal format (explained below) and the punctuation following each item has no effect on the output.
 

END

The optional END may be used after the last data item. If USING is not specified, then END: 1) suppresses the EOL sequence from being output after the last item, 2) sends an EOI signal with the last character of the last item sent to a IEEE-488 device, and 3) truncates a file.
 
If USING is specified, then END: 1) suppresses the EOL sequence only when no data is output from the last output item, 2) sends EOI with the last character of the last item (unless no data is sent from the last item) and 3) truncates a file. A comma before END will output an item terminator (a comma for numeric items or a CR/LF for string items).
 

USING

See IMAGE for a complete explanation of the image list. The items specified in the image list are acted upon as they are encountered. Each image list item should have a matching output item. Processing of the image list stops when no matching output item is found. Conversely, the image list is reused starting at the beginning to provide matches for all remaining output items. FORMAT ON is used in connection with OUTPUT USING, even if FORMAT OFF has been specified.
 
OUTPUT USING is not allowed to ASCII files. Use BDAT or regular files or if necessary, do the OUTPUT USING to a string and then OUTPUT the string to the ASCII file.
 

Internal Format (FORMAT OFF)

The internal format for an INTEGER is a two byte, two's complement, binary integer. LSB/MSB FIRST (see ASSIGN) can be used to specify the order in which the two bytes are sent or received. Internally, the order is stored in the form most natural to the computer's processor.
 
The internal format for REAL numbers is an eight byte, IEEE compatible floating point number (see IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std. 754-1985). As with integers, LSB/MSB FIRST can be used to determine the byte ordering during I/O statements.
 
A COMPLEX number is stored internally as two real numbers.
 
The internal format for strings depends on the source/destination of the I/O statement. The string format for devices and BDAT files consists of a string length followed by the string contents. Specifically, a four byte integer is sent/received first. The integer specifies the length of the string. The actual string is then sent/received. An even number of bytes is always sent/received, therefore, if the string is odd in length an extra padding byte is sent/received. As with integers, LSB/MSB FIRST  can be used to determine the byte ordering of the integer length.
 
For regular files, the internal format for strings is a null-terminated string. For ASCII files FORMAT ON/OFF has no affect. Data is always stored as ASCII strings proceeded by a two byte length and padded by a space if necessary to make the string length even. The string length is always stored with MSB FIRST.
 

Records

When outputing to a file, you may specify a record number. The first record in the file is record 1. The record size for BDAT files is specified when the file is created and defaults to 256 bytes. For other file types the record size is 1; thus the record number is actually the offset into the file. The first byte of the file is at offset 1. When a record number is specified and the record size is not 1, if the OUTPUT produces more data than a single record, an End of Record error or event occurs.
 

OUTPUT KBD Porting

Three editor functions have been added to HTBasic and should not be used in programs that will be executed with HP BASIC: DEL LEFT, NEXT WORD and PREV WORD. Otherwise, all the two-character function key sequences ( CHR$(255)&CHR$(X) ) used by HP BASIC are compatible with HTBasic. If multiple statements are output in a single OUTPUT KBD statement, they are all executed before the next BASIC line. HP BASIC sometimes intermixes the execution with multiple BASIC lines, based on the presence or absence of "closure keys."
 
See Also: