Differences Between the WordBasic Write and Print Commands

Last reviewed: July 30, 1997
Article ID: 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, "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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.