Format
PRINT# constant1, printobject1 [NONULL]
Description
This statement is used to write integers, decimals and strings to disk.
Constant1 identifies the file number that the file was opened as. This
must be a constant with a value of 1, 2 or 3. The file must have been
previously opened with the OPEN command. If printobject1 is a string, you
can also add the optional argument "NONULL", which will cause ASIC to
suppress the trailing NULL character it would normally write to disk. DOS
errors are returned in the system variable "ERROR". A list of these error
codes may be found in the error messages section of the ASIC Manual. Also,
refer to the technical details section of the ASIC Manual for more
information on the format in which ASIC writes the data to disk.
Example
PRINT# 1, "HELLO"
IF ERROR = 255 THEN DISKFULL:
PRINT# 1, "WORLD"
IF ERROR = 255 THEN DISKFULL:
After successful execution of the print statements the file identified by
file number 1 would contain "HELLO0WORLD0" . Note that the "0" following
HELLO and WORLD in our example represents the ASCII null character.
Strings in ASIC are always internally terminated with ASCII null
characters. By default, these nulls are also written to disk.
PRINT# 2, "HELLO" NONULL
In this example, the string "HELLO" would be written to file #2, and no
trailing NULL will be written to disk.
PRINT #3, 1234
In this example, the number "1234" would be written to file #3 as two bytes
in Intel binary format (the file would contain the two hexadecimal bytes:
D2 04).
Comments
Note that while ASIC doesn't generate carriage returns and line feeds for
you as it does with the PRINT command, you can write these characters to
disk as follows:
A$=CHR$(13)
B$=CHR$(10)
A$ = A$ + B$
PRINT #1, A$
You might be wondering about the purpose of the NONULL option. ASIC
normally writes trailing NULLs with strings. This is desirable if you plan
to read the file exclusively with other ASIC programs.
However, sometimes you may want to write a string for use by another
program. In this case, the NULL character sometimes confuses the other
program. Specifying the NONULL option will cause ASIC to suppress the
offending NULL character.
What happens if you read a string that is terminated by a Carriage
Return/Line Feed Sequence (such as GWBASIC/BASICA produces)? In this
instance, specify the CRLF option on the INPUT# statement. Then ASIC will
read the string until it finds a CR/LF or until it reads 80 characters,
whichever comes first.
See Also
|