Using VBScript with Printer Code Modifiers

Use the Printer Code Modifier functionality of BarTender to modify print code that is being sent to a printer or printer code template. By using Printer Code Modifier Actions, you can easily search the print code and replace text, insert text, or delete text by using the BarTender interface.

If you want to modify print code beyond the simple search and replace functions in the Search and Replace (Printer Code Modifier) dialog, you can create custom Visual Basic Script (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 run the Print command or export a printer code template, BarTender stores the contents of the print code in an internal object that is called PCM. To access the print code in a VBScript, you must refer to this object, read each line of the print code, modify the contents of the line as necessary, and then rewrite each line to produce a final print code output.

Example

'The variable that is 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 that is being read

variableLine = PCM.ReadLine()

'Check to determine whether the line of code needs to be modified

If variableLine = "My criteria" Then

'Check to verify 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