將 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

相關主題