Validation Script - How To Abort? 追蹤

Legacy Poster

I'm using Bartender Enterprise 8.01 and just used VBScripting for the first time.  My script is simply taking a date entered from a prompt and adding two years.  I've added some error checking but I can't figure out how to report the error to the user.  For example let's say they entered an invalid date at the prompt, I can check for that in the script but then what?  Do I throw an exception?  (if VBS even supports them)  Do I set some unknown global variable to false or set an error message?  How can I report an error condition to the user and abort the print process from continuing?


side note: I checked the Help but it's not much help (or value) on the scripting side of things.


Thanks for any help.



1 意見

Domingo Rodriguez
評論操作 永久連結

You could make use of te Format.CancelPrinting () function:


Format.CancelPrinting Function



Displays prompt that either cancels printing, or allows user to cancel printing.


Format.CancelPrinting(Message, ContinueButtonLabel)



Message is a string containing the text of the prompt dialog.

ContinueButtonLabel is an optional string containing the name of the "Continue" button.


The Format.CancelPrinting function displays a prompt that allows the user to cancel the print job manually. Alternatively, this function can display a prompt that simply informs the user that the print job is cancelled. If ContinueLabelButton is null (""), the user cannot prevent the cancellation of the print job and the message has only an OK button. If ContinueLabelButton is omitted from the Format.CancelPrinting function, the resulting dialog contains a Cancel button, as well as a Continue button. If ContinueLabelButton is present and not null, it specifies the label of the second button.


The following example demonstrates the Format.CancelPrinting function in use. The code checks the number of serialized labels. If the number of serialized labels is greater than 1000, BarTender will display a prompt dialog that informs the user that there are too many labels. This dialog has a single OK button. If the number is between 500 and 1000 serialized labels, BarTender displays a prompt that gives the user the option of cancelling the print job or letting it continue. This prompt will have a Cancel button and a Print Anyway button.


If Format.NumberSerializedLabels > 1000 Then

    Call Format.CancelPrinting("Too Many Labels. Job is being cancelled.", "")

ElseIf Format.NumberSerializedLabels > 500 AND Format.NumberSerializedLabels < 1000 Then

    Call Format.CancelPrinting("500-1000 Labels. Do you want to cancel?", "Print Anyway")

End If