Write# (statement)

Syntax

Write [#]filenumber [,expressionlist]

Description

Writes a list of expressions to a given sequential file.

Comments

The file referenced by filenumber must be opened in either Output or Append mode.

The filenumber parameter is an Integer used by the Basic Control Engine to refer to the open fileā€”the number passed to the Open statement.

The following table summarizes how variables of different types are written:

 

Data Type

Description

 

Any numeric type

Written as text. There is no leading space, and the period is always used as the decimal separator.

 

String

Written as text, enclosed within quotes.

 

Empty

No data is written.

 

Null

Written as #NULL#.

 

Boolean

Written as #TRUE# or #FALSE#.

 

Date

Written using the universal date format:

  #YYYY-MM-DD HH:MM:SS#

 

User-defined errors

Written as #ERROR ErrorNumber#, where ErrorNumber is the value of the user-defined error. The word ERROR is not translated.

 

The Write statement outputs variables separated with commas. After writing each expression in the list, Write outputs an end-of-line.

The Write statement can only be used with files opened in Output or Append mode.

Example

This example opens a file for sequential write, then writes ten records into the file with the values 10...50. Then the file is closed and reopened for read, and the records are read with the Input statement. The results are displayed in a dialog box.

Sub Main()

  Open "test.dat" For Output Access Write As #1

  For x = 1 To 10

    r% = x * 10

    Write #1,x,r%

  Next x

  Close

  msg1 = ""

  Open "test.dat" For Input Access Read As #1

  For x = 1 To 10

    Input #1,a%,b%

    msg1 = msg1 & "Record " & a% & ": " & b% & Basic.Eoln$

  Next x

  MsgBox msg1

  Close

End Sub

See Also

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

More information

W