Sign in to follow this  
Followers 0
meetrix

Question

10 posts in this topic

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

Share this post


Link to post
Share on other sites



$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]

Share this post


Link to post
Share on other sites

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")

Share this post


Link to post
Share on other sites

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#10 ·  Posted

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 Then

could just be:

If StringLen($s_serial) <> 16 Then

You 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]

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  
Followers 0