Print# (statement)

Syntax

Print #filenumber, [[{Spc(n) | Tab(n)}][expressionlist][{;|,}]]

Description

Writes data to a sequential disk file.

Comments

The filenumber parameter is a number that is used by the Basic Control Engine to refer to the open file, the number passed to the Open statement.

The following table describes how data of different types is written:

 

Data Type

Description

 

String

Printed in its literal form, with no enclosing quotes.

 

Any numeric type

Printed with an initial space reserved for the sign (space = positive). Additionally, there is a space following each number.

 

Boolean

Printed as TRUE or FALSE.

 

Date

Printed using the short date format. If either the date or time component is missing, only the provided portion is printed (this is consistent with the "general date" format understood by the Format/Format$ functions).

 

Empty

Nothing is printed.

 

Null

Prints NULL.

 

User-defined errors

Printed to files as "Error code", where code is the value of the user-defined error. The word "Error" is not translated.

 

Each expression in expressionlist is separated with either a comma (,) or a semicolon (;). A comma means that the next expression is output in the next print zone. A semicolon means that the next expression is output immediately after the current expression. Print zones are defined every 14 spaces.

If the last expression in the list is not followed by a comma or a semicolon, then an end-of-line is printed to the file. If the last expression ends with a semicolon, no end-of-line is printed¾the next Print statement will output information immediately following the expression. If the last expression in the list ends with a comma, the file pointer is positioned at the start of the next print zone on the current line.

 

The Write statement always outputs information ending with an end-of-line. Thus, if a Print statement is followed by a Write statement, the file pointer is positioned on a new line.

The Print statement can only be used with files that are opened in Output or Append mode.

The Tab and Spc functions provide additional control over the file position. The Tab function moves the file position to the specified column, whereas the Spc function outputs the specified number of spaces.

In order to correctly read the data using the Input# statement, you should write the data using the Write statement.

Example

Sub Main()
  'This example opens a file and prints some data.
  Open "test.dat" For Output As #1
  i% = 10
  s$ = "This is a test."
  Print #1,"The value of i=";i%,"the value of s=";s$

  'This example prints the value of i% in print zone 1 and s$ in
  'print zone 3.
  Print #1,i%,,s$

  'This example prints the value of i% and s$ separated by ten spaces.
  Print #1,i%;Spc(10);s$

  'This example prints the value of i in column 1 and s$ in column 30.
  Print #1,i%;Tab(30);s$

  'This example prints the value of i% and s$.
  Print #1,i%;s$,
  Print #1,67

  Close #1
  Kill "test.dat"
End Sub

See Also

Open (statement); Put (statement); Write# (statement).

Note

The end-of-line character can be either the carriage-return/line-feed pair, or the line-feed character.

If you want it to go to a file you need the # otherwise it goes to standard out and uses the first variable (in thise case f) as the first item to output to standard out.  So that print line should be

Print #F, "This is a test"

More information

P