Write

Syntax

Write #FileNumber, Expression1[$] [, Expression2[$]] [¼]

Remarks

Writes the specified expressions to an open sequential file. FileNumber is the number specified in the Open instruction that opened the file for output or appending. For more information about sequential files, see Chapter 9, "More WordBasic Techniques," in Part 1, "Learning WordBasic."

Write is similar to the Print statement, but instead of separating the expressions with tab characters, Write separates them with commas; also, Write encloses strings in quotation marks. This allows the resulting values to be read by a Read instruction. For an illustration of the respective output of the Print and Write statements, see Print.

Example

This example opens a sequential file for output (creating it if it does not already exist), prompts the user for three pieces of data, and then uses the Write statement to insert the data into the sequential file:


Open "DATAFILE.TXT" For Output As #1
name$ = InputBox$("Enter name:")
age = Val(InputBox$("Enter age:"))
job$ = InputBox$("Enter occupation:")
Write #1, name$, age, job$
Close #1

The following is an example of a paragraph in DATAFILE.TXT inserted by the Write statement:


"Michelle Levine", 26,"Dancer"

See Also

Close, Eof(), Input, Input$(), Line Input, Lof(), Open, Print, Read, Seek