Syntax
Print [#FileNumber,] Expression1[$] [; or , Expression2[$] [; or , ¼]
Remarks
Displays the specified expressions in the status bar, or if you specify FileNumber, sends the expressions to the sequential file associated with that number. Unlike MsgBox, which accepts only strings, Print accepts strings, string variables, numbers, and numeric variables, and allows you to mix all these types.
You can join strings and string variables with the plus sign (+). You can join strings and numbers with a semicolon (;) or a comma (,). A comma inserts a tab between values.
Note
Print automatically adds a space before positive numeric values; there is no need to include an extra space in a string that precedes one. Print does not add a space before negative numeric values.
Like Write, the Print statement can send expressions to a sequential file. However, the expressions are formatted differently in the file, as illustrated in the following table. Note that Print separates the expressions with a tab character.
WordBasic instruction | Line created in sequential file #1 |
Print #1, "Phil", "Teacher" | Phil Teacher |
Write #1, "Phil", "Teacher" | "Phil","Teacher" |
Examples
This example displays the following sentence in the status bar: "March sales were 2500 and May sales were 3600 for a total of 6100."
mar = 2500 may = 3600 Print "March sales were"; mar ; " and May sales were" \ ; may ; " for a total of" ; mar + may ; "."
The following example displays this line on the status bar: "Juan Garcia 32 1234".
name$ = "Juan Garcia" age = 32 employeeNum = 1234 Print name$; age; employeeNum
The following example sets up a sequential file for use as a text-only data source in a mail-merge operation. The first Print instruction inserts column headings; the second adds a data record. Items in a given Print instruction are inserted into a single paragraph and are separated by tabs. Note that WordBasic doesn't have a sequential-file-access instruction that can read tab-delimited data. To see the results, you must open the sequential file as you would any Word document.
Open "DATA.TXT" For Output As #1 Print #1, "Name", "Address", "Occupation" Print #1, "Juan Garcia", "123 Main St", "Accountant" Close #1
See Also
Close, Eof(), Input, Input$(), Line Input, Lof(), MsgBox, Open, Read, Seek, Write