Using VBScript with Printer Code Modifiers

The Printer Code Modifier functionality of BarTender enables modification of print code being sent to a printer or printer code template. Using Printer Code Modifier Actions, you can easily search the print code and replace text, insert text, or delete text using the BarTender interface. If you want to modify print code beyond the simple "Search and Replace" functions in the Action List dialog, you can create custom VBScript to modify print code output before it is sent to the printer or printer code template. By using VBScript, you can have complete control over the print code output.

When you execute the Print command or export a printer code template, BarTender stores the contents of the print code in an internal object called PCM. To access the print code in a VBScript, you will need to refer to this object, read each line of the print code, modify the contents of the line as necessary, and rewrite each line to produce a final print code output.

Example

'The variable found defines whether the portion

'of code has already been modified

'Initially, the code has not been modified, and is set to False

found = False

'Read each line of print code in the object PCM

Do Until PCM.FileAtEOF

'Define a variable that holds the line of print code being read

variableLine = PCM.ReadLine()

'Check to see if the line of code needs to be modified

If variableLine = "My criteria" Then

'Check to see that the line has not already been modified

If found = False Then

'Modify the contents of the line

PCM.WriteLine("My New Value")

'Set found to True

found = True

Else

'If none of the previous are true,

'rewrite the unmodified line to PCM

PCM.WriteLine(variableLine)

End If

End If

Loop

Related Topics