meetrix Posted May 9, 2006 Share Posted May 9, 2006 Hello All, I have the following script that prompts for a serial number. The serial should be 16 digits long. So, how can I set the script to check that 16 digits have been entered, and if it is less than 16 digits to give a message to correct the problem. $Loop = 1 While $Loop = 1 $s_serial = InputBox("Report", "Serial Number."&@CRLF&"Then Click OK to proceed.") If @error = 1 Then $answer = MsgBox(4, "WARNING!", "You pressed 'Cancel', Do you want to Exit?") If $answer = 6 Then Exit EndIf Else If $s_serial = "" Then MsgBox(4096, "ERROR", "You Must Enter a Serial Number- try again!") Else $Loop = 0 EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
herewasplato Posted May 9, 2006 Share Posted May 9, 2006 $s_serial = InputBox("Report", "Serial Number." & @CRLF & "Then Click OK to proceed.") If StringLen($s_serial) <> 16 Then MsgBox(0, "", "wrong size") [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
meetrix Posted May 9, 2006 Author Share Posted May 9, 2006 It works, but How do I make the script return back to the prompt input if less than 16 digits? $s_serial = InputBox("Report", "Serial Number." & @CRLF & "Then Click OK to proceed.") If StringLen($s_serial) <> 16 Then MsgBox(0, "", "wrong size") Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2006 Moderators Share Posted May 9, 2006 It works, but How do I make the script return back to the prompt input if less than 16 digits?I think the better question is "What have you tried?" What makes something continue until you tell it not to? (A loop?)While 1 $s_serial = InputBox("Report", "Serial Number." & @CRLF & "Then Click OK to proceed.") If StringLen($s_serial) = 16 Then MsgBox(64, "Info", "Right Size") ExitLoop EndIf WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
herewasplato Posted May 9, 2006 Share Posted May 9, 2006 While 1 $s_serial = InputBox("Report", "Serial Number." & @CRLF & "Then Click OK to proceed.") If @error = 1 Then $answer = MsgBox(4, "WARNING!", 'You pressed "Cancel". Do you want to Exit?') If $answer = 6 Then Exit Else If $s_serial = "" Or StringLen($s_serial) <> 16 Then MsgBox(4096, "ERROR", "You Must Enter a 16 digit Serial Number - try again!") Else ExitLoop EndIf EndIf WEnd [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
herewasplato Posted May 9, 2006 Share Posted May 9, 2006 (edited) ...less than 16 digits?You will have to change the code that I posted if you only want to check for "less than".I check for both "less than" and "greater than". Edited May 9, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
meetrix Posted May 9, 2006 Author Share Posted May 9, 2006 Thanks, I will remember that. A thought crossed my about the old autoit where you could do a goto label and re-retry again.. I think the better question is "What have you tried?" What makes something continue until you tell it not to? (A loop?)While 1 $s_serial = InputBox("Report", "Serial Number." & @CRLF & "Then Click OK to proceed.") If StringLen($s_serial) = 16 Then MsgBox(64, "Info", "Right Size") ExitLoop EndIf WEnd Link to comment Share on other sites More sharing options...
meetrix Posted May 9, 2006 Author Share Posted May 9, 2006 Thank you.. I will try and let you know...have a good one. While 1 $s_serial = InputBox("Report", "Serial Number." & @CRLF & "Then Click OK to proceed.") If @error = 1 Then $answer = MsgBox(4, "WARNING!", 'You pressed "Cancel". Do you want to Exit?') If $answer = 6 Then Exit Else If $s_serial = "" Or StringLen($s_serial) <> 16 Then MsgBox(4096, "ERROR", "You Must Enter a 16 digit Serial Number - try again!") Else ExitLoop EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted May 9, 2006 Share Posted May 9, 2006 one quick thing you dont need to add the question mark in ur topic, i think we got the point that ur asking a question Link to comment Share on other sites More sharing options...
herewasplato Posted May 9, 2006 Share Posted May 9, 2006 Thank you.. I will try and let you know...have a good one.You are welcome.FYI, you can drop the "Or" if you wish:If $s_serial = "" Or StringLen($s_serial) <> 16 Thencould just be:If StringLen($s_serial) <> 16 ThenYou should get the same result.Depending on the format of the serial number, you might also look at StringStripWS - since 16 spaces will pass that simple "<>" check. Also StringInStr might help further the check or StringRegExp in the beta version. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now