Jump to content

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:.

Thanks

Chris

CODE
;

; 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.

$siteCode="50144397"

$finished=0

while $finished=0

$exitLoop=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

WEnd

$exitLoop=0

while $exitLoop=0

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

If @error = 1 Then

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

Exit

EndIf

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

WEnd

;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

$check=0

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

for $loop = 1 to 18

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

Next

for $loop = 1 to 17 step 2

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

Next

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

$check = 1000-$check

; Print the success message

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

$check=0

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

if $check<>6 Then

$finished=1

EndIf

WEnd

; Finished!

Link to comment
Share on other sites

  • Developers

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)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...