The PrintString method can be used to
print the contents of a buffer to your Windows printer. Formatting,
like carriage returns and line feeds, can be added through standard
scripting methods. See the example below.
- Parameters
- PrintStr
- Name of string to print.
- FlagVal
- Specifies whether or
not you want the printer dialog to be displayed. Setting this value
to a 1 or true causes the standard Windows printer selection dialog
to be displayed. Omitting this value or setting it to 0 or false causes
the string or string value to be sent directly to the default printer.
- Returns
- None.
- Remarks
- Can be used with or without the Optional Printer Dialog Flag.
Page numbers (including the word "Page") automatically print at
the bottom center of each page.
When the data is sent to the
printer, a system beep sounds.
- Example
- In the following example, the script checks to see if it is on
the correct screen (by searching for the string “===> ENTER”) then it goes to position row 18, column 12, of the screen, reads
in the next 75 characters and places them into buffer one. Then it
goes to position row 21, column 13, of the screen, reads in the next
75 characters and places them into buffer two. Then, it assigns the
value of buffer 1 plus a carriage return and line feed, plus an additional
line feed, plus the value of buffer 2 to "page". Then it prints the
contents of "page" (shown in red).
dim TextFound, Buf1, Buf2, page
Sub Main
EMConnect( "A" )
' This is to make sure you are on the correct screen
TextFound = EMSearch( "===> ENTER", 1, 1 )
If TextFound = 0 then
MsgBox "You are on the correct screen, you may continue!", 4096
EMReadScreen Buf1, 75, 18, 012
EMReadScreen Buf2, 75, 21, 013
End If
Page = Page + Buf1 + VbCrLf + VbLF + Buf2
MsgBox "Make sure your printer is ready and click OK to print!", 4096
PrintString Page
End Sub
Main
Note: Optionally, you can prompt the
user with the standard Windows printer selection dialog by including
the optional prompt parameter as shown here:
PrintString Page, 1
- Additional remarks
- The following application of this script describes how to print
a customer account number followed by the customer's address:
- In EMSearch, substitute a unique screen identifier
for "===> ENTER". Find a text string on the screen
where the customer data is displayed. It is good practice to create
scripts in such that way that they can only run on the screen that
they were designed for.
- In the first EMReadScreen, substitute the exact
cursor position where the Customer Number field
starts. You may have to decrease the number of characters to read.
- In the second EMReadScreen, substitute the exact
cursor position where the Customer Address field
starts.
- Test the script by running it. Most addresses consist of three
lines. You may have to do a little work to get the formatting of the
print job exactly the way you want it.
Tip: You can also modify this script to "read in"
a large amount of text (data), format the text, and send it to your
printer.