Read

Syntax

Read #FileNumber, Variable1[$] [Variable2[$]] [Variable3[$]] [, ¼]

Remarks

Retrieves string or numeric values from an open sequential file, typically containing data added with the Write statement, and assigns the values to variables. FileNumber is the number specified in the Open instruction that opened the file for output. For more information about sequential files, see Chapter 9, "More WordBasic Techniques," in Part 1, "Learning WordBasic."

Read is similar to Input, but removes quotation marks from strings. For example, a text-only paragraph created with a Write instruction might appear as follows:


"Michelle Levine", 26,"Dancer"

Whereas Input interprets the first value as "Michelle Levine", Read takes only the text within the quotation marks: Michelle Levine.

Example

This example reads each paragraph in the sequential file in turn and defines name$ as the first item and age as the second item. For each paragraph, the values are displayed in a message box.


Open "DATA.TXT" For Input As #1
While Not Eof(1)
Read #1, name$, age
MsgBox name$ + " is" + Str$(age) + " years old."
Wend
Close #1

See Also

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