Outputs formatted text to a file or device
Syntax
Print # filenum , Using formatstring ; [ expressionlist ]
Parameters
filenum
A file number of an open file or device.
formatstring
Format string to use.
expressionlist
List of items to print, separated by commas or semi-colons.
Description
Output various expressions to a text file or device using a format determined by the formatstring parameter. Internally, Print Using uses a buffer size of 2048 bytes, while it is highly unlikely that this buffer would be filled, it should be noted that output would be truncated should this limit be reached.
If no expression list is given, nothing will be output (note that the semi-colon after the format string is still necessary, even if no expression list is given).
The format string dictates how the expressions are to be formatted when output, indicated by the use of special marker characters. There are markers for formatting both string and numeric output:
String formatting
Marker | Formatting |
! | prints the first character of a string |
\ \ | prints as many characters of a string as occuppied between the pair \ \ |
& | prints the entire string |
Numeric formatting
Marker | Formatting |
# | placeholder for a digit |
. | placed near # indicates place for the decimal point |
+ | prints the sign of the number when placed to the left of numeric formatting |
^^^^ | prints exponential notation when placed to the right of numeric formatting |
All of the special marker characters can be escaped, or preceded, with the underscore character
"_", allowing them to be printed directly (
"_!" prints
"!").
If a numerical value can't be formatted in the form indicated by the format string, the formatting is ignored and the number is printed preceded by the percent
"%" character. E.g., the number
2E+200 with a
formatstring of " ##.## " would be printed as
"%2E+200".
All other characters within the format string are printed as they appear.
The
Using keyword is used with a different meaning with the
Palette graphics command
Example
Const filename As String = "file.txt"
Dim filenum As Integer = FreeFile()
If 0 <> Open(filename, For Output, As filenum) Then
Print "error opening " & filename & " for output."
End -1
End If
Print #filenum, Using "This file is called '&'"; filename
Print #filenum, "Some numerical values are:"
Print #filenum, Using "'###', '+###.###'"; 123.456, -123.456
Close(filenum)
will produce the file:
This file is called "file.txt"
Some numerical values are:
'123', '-123.456'
Differences from QB
- In QB a not-to-be-formatted expressionlist could be entered before the Using clause;
See also