Microsoft KB Archive/96731

{|
 * width="100%"|

Differences Between the WordBasic Write and Print Commands

 * }

Q96731

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c

-

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, &quot;Phil&quot;, &quot;Teacher&quot;     Phil [tab character] Teacher Write #1, &quot;Phil&quot;, &quot;Teacher&quot;    &quot;Phil&quot;,&quot;Teacher&quot; 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 &quot;c:\windows\temp\data.txt&quot; For Output As #1 Print #1, &quot;Name&quot;, &quot;Address&quot;, &quot;Occupation&quot; Write #1, &quot;Juan Garcia&quot;, &quot;123 Main St&quot;, &quot;Accountant&quot; Close #1 End Sub

Text File Results
Name [tab character] Address [tab character] Occupation &quot;Juan Garcia&quot;,&quot;123 Main St&quot;,&quot;Accountant&quot;