Jump to content
Sign in to follow this  

Can't Cancel from InputBox

Recommended Posts


Hi - wondering if anyone out there can help me.

Trying to do a little dialog to generate the check digit for an SSCC number (used in Logistics to identify transport units). The code to generate the number works great, but I can't seam to get it to cancel the script if the cancel button is pressed (or indeed the window is closed).

Trying to use the line 'If @error = 1 Then Exit' after the InputBox, but it keeps seeing this as a failed validation and asking for the lot number again. Any idea why the code won't stop? I've included the full code at the end.

Was also nice to know the reason the code wouldn't work on the Windows 98 machines downstairs was it needed to be recompiled as I'd developed it on an XP machine - but I'm hardly doing _anything_ :rolleyes:.




; AutoIt Version: 3.0

; Language: English

; Platform: Win9x/NT

; Author: Chris Meacher


; Script Function:

; Calculates check digit for SSCC.


; V1.0 12/06/07 0 Initial Draft

; Prompt the user to enter the lot nnumber.



while $finished=0


$lot ="F" & stringright(@year,2)

while $exitLoop=0

$lot = string(InputBox("SSCC CheckDigit Step 1of2", "Enter the pallet lot number", $lot))

If @error = 1 Then Exit

if StringLen($lot)=9 and StringIsInt(StringRight($lot,6)) then $exitloop=1



while $exitLoop=0

$seg = string(InputBox("SSCC CheckDigit Step 2of2", "Enter the pallet segment"))

If @error = 1 Then

msgbox(4096,"Cancel","pressed cancel")



if StringLen($seg)<=3 and $seg<>"" and StringIsInt($seg) then $exitloop=1


;pad with leading 0's

if StringLen($seg)=1 then $seg = "0"&$seg

if StringLen($seg)=2 then $seg = "0"&$seg

$SSCC = $siteCode&stringright($lot,6)&$seg


;MsgBox(4096,"SSCC", "SSCC: "&$SSCC)

for $loop = 1 to 18

$check = $check+int(StringMid($SSCC,$loop,1))


for $loop = 1 to 17 step 2

$check = $check+2*int(StringMid($SSCC,$loop,1))


;MsgBox(4096,"SSCC", "count: "&$check)

$check = 1000-$check

; Print the success message

MsgBox(4096,"SSCC", "Check Digit: "&StringRight(string($check),1))


$check = msgbox(4100,"Again?","Run another?")

if $check<>6 Then




; Finished!

Share this post

Link to post
Share on other sites

the 'If @error = 1 Then Exit' is done on String() not InputBox, since that is the last command performed.

change it to:

$seg = InputBox("SSCC CheckDigit Step 2of2", "Enter the pallet segment")

If @error = 1 Then

$seg = String($seg)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.