PRINT#

Function

PRINT# writes data to file.

Syntax

PRINT#file no,var1 ;var2;….varX

Examples

PRINT#4,A$;B4;D$

PRINT#1,X;Y;Z

The variables specified are written to the appropriate file nunber.

Remarks

Variables should be separated by semicolons and not commas. As PRINT# outputs to the file in the same way as it would to the screen, any spaces present if commas were used would also be written to the file.

Care should be taken when writing string data to files as they should not contain any commas, semicolons, leading blanks, carriage returns or line feeds as they would be interpreted as delimiting characters. If it is necessary to include any delimiting characters in a string the variable name should be enclosed in double quotes by using CHR$(34).

For example, if A$=”TOM,DICK” and B$=”HARRY”. The statement:

PRINT#2,A$;B$

would write the following to the file:

TOM,DICKHARRY

and the statement:

INPUT#2,A$,B$

would input ‘TOM’ to A$ and ‘DICKHARRY’ to B$.

To separate the data correctly the following format should be used:

PRINT #2,CHR$(34);A$;CHR$(34);CHR$(34);B$;CHR$(34)

This would write the following to the file:

"TOM,DICK","HARRY"

and the statement:

INPUT#2,A$,B$

inputs ‘TOM, DICK’ to A$ and ‘HARRY’ to B$

The statement WRITE# is a simpler way to perform the above functions.