Format.CancelPrinting within OnProcessData 'if' statements 追蹤
Hi all, I've been trying to get this working for several days now, but I can't seem to figure it out.
Background: The idea is that there is a Data Entry Form, in which an ID can be put in with a barcode-scanner, and a weight with a connected scale. The ID will be used to look-up data in a .xls 'database', which will populate fields on the label. The weight will also be stored in the .xls file, and printed on the label. However, the input in the weight will need to be validated, as the scale can return 0 (zero) or negative values. The operator needs to be notified of the incorrect weight and brought back to the Data Entry Form.
For this, I thought a VBScript in the seed_weight_number OnProcessData event could handle that. However, when I try to cancel the print-job within my 'if' statements using the call Format.CancelPrinting() function, no popup is given. Messageboxes (Msgbox) before and after the CancelPrinting are activated. If I move the Format.CancelPrinting outside of my 'if' statements, it works fine, but then it is always triggered of course.
Can someone help me figure this out?
Moving the code to OnNewRecord does give the correct message, but there is no option to go back to the Data Entry Form when the print is cancelled there. Same for OnPostPrompt.
Edited to add: I work with BarTender Designer 2016 R9, with Automation license, version 18.104.22.16860 (64 bit), on Windows 10 Enterprise
dim inputValue, inpLen, inStrRes
inputValue = Format.Objects("seed_weight_number").Value
inStrRes = InStr(inputValue, "-")
If ( (Len(inputValue) > 0) and IsNumeric(inputValue) ) Then
If ( (inStrRes > 0) or (inputValue = "0") ) Then
Msgbox "Before Format.CancelPrinting" 'Is called correctly
call Format.CancelPrinting("The weight cannot be negative or zero. Please check the weight on the scale and try again. Note: this weight will not be stored in the database.")
Msgbox "After Format.CancelPrinting" 'Is also called correctly
'call Format.CancelPrinting("Control message outside of 'if' section.") 'If activated, is called correctly before all other messages