Differences Between the WordBasic Write and Print Commands

ID: Q96731

The information in this article applies to:

SUMMARY

Both the WordBasic Print and Write commands can be used to write text to a sequential file. However, the commands cause the information to be written to the text file differently.

MORE INFORMATION

The Write command places quotation marks around all text values (but not numeric data) and separates two or more values on the same command line with commas. The WordBasic Read command retrieves values from a text-only file created with the Write statement (removes quotation marks from strings).

The Print command separates two or more values on the same command line with a tab character and does not enclose the data in quotation marks.

WordBasic Instruction           Resulting Line in Sequential File #1
---------------------           ------------------------------------
Print #1, "Phil", "Teacher"     Phil [tab character] Teacher
Write #1, "Phil", "Teacher"     "Phil","Teacher"

The Print and Write commands automatically add a space before positive numeric values and add no space before negative numeric values.

The following example sets up a sequential text-only file. The Print instruction inserts column headings, and the Write command adds a data record.

Sub MAIN
Open "c:\windows\temp\data.txt" For Output As #1 Print #1, "Name", "Address", "Occupation" Write #1, "Juan Garcia", "123 Main St", "Accountant" Close #1
End Sub

Text File Results

Name [tab character] Address [tab character] Occupation "Juan Garcia","123 Main St","Accountant"

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 269 and 338

Kbcategory: kbusage kbmacro KBSubcategory: Additional query words: winword2 2.0 2.0a 2.0a-CD 2.0b 2.0c word6 winword file input output sequential 6.0

Version           : 1.x 2.x 6.0 6.0a 6.0c
Platform          : WINDOWS

Last Reviewed: July 30, 1997