Stop Printing Using Vbscript Follow

0
Avatar
Legacy Poster

I am using the scale control that is auto printing whenever it reaches a stable weight. However I want to stop the printing if certain conditions occur. I thought I could do this in the OnPrintJobStart event under VB Scripting however it would print before running the event. I am using a named data source to hold the weight and another to store the previous weight. Here is my question:

 

Can I write the VB Script in the OnProcessData event of the named data source so that I can stop the print job before it even gets started if the conditions are met?

 

If IsNumeric(Value) then
    Dim difference
    difference = 0
    difference = ABS(CInt(Value) - CInt(Format.NamedSubStrings("PreviousWeight").Value))  
    
    If difference < 5 then
              Call Format.CancelPrinting("Print Cancelled", "") 
    End If
End  If
 
This is the code I want to use. If the weight of the next item is less than 5 pounds of the previous I do not want to print the label at all.
 
Thank you.

3 comments

0
Avatar
Canguita
Comment actions Permalink

Hello,

 

About your issue:

 

1. Is ABS the weight from the scale? If yes, please note that very probably your scale is getting also the units (kilograms, grams, pounds,...) so you will need discard them for converting to integer.

 

2. How are you stroring "PreviousWeight"? Is this initalized to 0 at the beggining?

 

3. What does it happen if ABS is less than Previous Weight? Difference will be a negative number and will not be printed.

 

4. In order to make sure that the values are properly updated, you will need to add your code in OnPostPrompt() event script.

 

Thanks,

 

Carlos

0
Avatar
Legacy Poster
Comment actions Permalink

Hi Carlos,

 

The Value is the Weight (embedded data) from the scale and I am using ABS to get the absolute value of the calculation so it should never return negative. Am I using this function incorrectly? 

 

I have the "Previous Weight" stored as Embedded Data under Named Data Sources and print it out on the next label (so that I know it is not being set back to zero). I set this value every time in the OnPrintJobEnd event and never initialize it to zero.

Format.NamedSubStrings("PreviousWeight").Value = Format.NamedSubStrings("Weight").Value So the current "Weight" is printed in large bold numbers and the "Previous" weight is printed in a smaller number on the lower left of the label. The Previous Weight does print out properly along with the weight. 
 
The print command is sent to the scale "W<CR>" by Bartender every 250 milliseconds and I only receive the value in Pounds back from the scale "<STX> 1400 lb <CR><LF>". It is a Doran scale so I had to create the protocol for it and it is working fine. I have it immediately print the label with the current weight and previous weight. The properties also wait for a stable weight for 5 seconds. However if for any reason the weight jumps or drops by even 1 pound for the pallet (not sure why it is doing this) it will print out another label. I want to give it a 5 pound birth before printing the next label. 
 
I will try adding this to the OnPostPrompt() event script. After looking it up in Bartender help it looks like the correct place to put it. Thank you.
 
Update*****************************************************************************************
 
I do not see an OnPostPrompt() event available for me to use. I looked through the Bartender Document Options --> VB Scripting and under the named data source properties --> Transforms -->  VB Script.
0
Avatar
Domingo Rodriguez
Moderator
Comment actions Permalink

Make sure that you use "Visual Basic Script" as the source for your data source, then choose "Even Control Scripts" as the "Script" type. Click the "Edit with Script Assistant..." button. You should now see the "OnPostPrompt" event under the event list.

Please sign in to leave a comment.