FormTextPrinter Reference
FormTextPrinter allows you to achieve separation of
code and data in a very easy and elegant way.
Form syntax
A form is a stream of text that can represent anything you would like to
print. For example it can be a ticket, a coupon, a personal info sheet or an
alert notice. The form contains special parameter tags which get replaced at run
time with dynamic information that you provide.
Example:
------------------------------------------------------------------------------
| You can use a fixed width font, like Courier, to edit the forms with ease.
| Price: %Price:10%
| The next price is right aligned: %Price:10:R%
| This text is padded %Description:40: %
------------------------------------------------------------------------------ |
The syntax of each parameter is: %<name>[:width[:flags[space padding]]]%
The only valid flag at the moment is 'R' which means that the content assigned
to the parameter will be aligned to the right.
More parameter examples:
- %Right Text:80:R%
- %Padded Param:: %
Object syntax
Name |
Declaration |
ClearForm |
Sub ClearForm() HRESULT ClearForm(); |
Description:
ClearForm resets all the values you had given to form parameters by
calling SetField.
Errors:
None. |
Codepage |
Property Codepage As Long HRESULT Codepage([out, retval]
long *pVal);
HRESULT Codepage([in] long newVal); |
Description:
The codepage that the printer is expecting to receive. See
codepages page for explanation.
Default:
System default ANSI codepage.
Errors:
E_INVALIDARG - On negative codepage numbers. |
Form |
Property Form As String HRESULT Form([out, retval] BSTR *pVal);
HRESULT Form([in] BSTR newVal); |
Description:
The form used at the moment.
Errors:
None. |
FormFile |
Property FormFile As String HRESULT FormFile([in] BSTR
newVal); |
Description:
Allows you to set a file as a source of the form data. File contents are
loaded into Form property.
You can supply text in a variety of encodings:
- SBCS - Single byte character set, as long as it is in the default
system ANSI codepage.
- UTF8 - UTF8 encoded Unicode text.
- UCS2 - Unicode text stored as two bytes per character.
If supplying Unicode text file, the file must have appropriate BOM mark as
the first character for identification. For example see notepad's behavior.
Errors:
E_ACCESSDENIED - On file access failure.
E_INVALIDARG - On invalid UTF8 encoding. |
Port |
Property Port As String HRESULT Port([out, retval] BSTR *pVal);
HRESULT Port([in] BSTR newVal); |
Description:
The port that the printer is connected to. See
ports page for explanation.
Default:
LPT1.
Errors:
None. |
PrintForm |
Sub PrintForm() HRESULT PrintForm(); |
Description:
Send the current form with all the parameter values to the printer.
Printing does not reset parameter values.
Errors:
See list of printing errors. |
SetField |
Sub SetField(Name As String, Value) HRESULT SetField([in]
BSTR Name, [in] VARIANT Value); |
Description:
Set the value of one of the parameters of the form.
Method Parameters:
-
Name - The name of the parameter as it appears in the form
data.
-
Value - The value to assign to the parameter. You can pass any
variant type that can be rendered as text. Passing 'null' will reset this
parameter.
Errors:
DISP_E_BADVARTYPE - The variant type is not a valid type of variant.
DISP_E_TYPEMISMATCH - The argument could not be coerced to the specified
type.
E_INVALIDARG - One of the arguments is invalid.
E_OUTOFMEMORY - Memory could not be allocated for the conversion. |
Timeout |
Property Timeout As Long HRESULT Timeout([out, retval]
long *pVal);
HRESULT Timeout([in] long newVal); |
Description:
How long to wait (in milliseconds) for the printer to respond.
Default:
Two seconds (2000 milliseconds).
Errors:
E_INVALIDARG - On negative timeout values. |
Copyright 2004 CodeBuildingBlocks
|