将 VBScript 与打印机代码修改器一起使用

使用 BarTender 的“打印机代码修改器”功能来修改发送到打印机或打印机代码模板的打印代码。使用打印机代码修改器操作,可以轻松地通过 BarTender 界面搜索打印代码、替换文本、插入文本或删除文本。

如果要在“搜索和替换(打印机代码修改器)”对话框中修改除简单的“搜索并替换”功能之外的打印代码,在将打印代码发送到打印机或打印机代码模板之前,可以创建自定义 Visual Basic 脚本 (VBScript) 来修改打印代码输出。通过使用 VBScript,可以完全控制打印代码输出。

当您运行打印命令或导出打印机代码模板时,BarTender会将打印代码的内容存储在称为PCM的内部对象中。要访问 VBScript 中的打印代码,您必须参考此对象,阅读每行打印代码,根据需要修改行的内容,然后重写每行以生成最终打印代码输出。

示例

'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 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

相关主题