Sign in to follow this  
Followers 0
computergroove

How do I make a mandatory mimimum # of Characters in InputBox?

7 posts in this topic

#1 ·  Posted (edited)

How do I make the $CustomerID and $CustomerPin be exactly 8 and 3 characters respectively. InputBox allows me to specify a max # of characters but how do I make a minimum? Also in the event that the end user inputs a wrong customerid and custoemrpin, is there a way to create a shortcut key to this part of the script?

$xmlfile = FileOpen("tiapp.xml", 0)

; Check if file opened for reading OK
If $xmlfile = -1 Then
    MsgBox(0, "Error", "Unable to open tiapp.xml")
    Exit
EndIf
While 1
    $chars = FileRead($xmlfile) ;reads the xml file and adds it to $chars
    $LeftCount = StringInStr($chars, "20000209_432") ;counts the # of left characters before the search string
    $LeftModified = ($LeftCount)-1 ;Subtracts 1 from the count so StringRight will start from correct position
    $RightString = StringTrimLeft($chars, $LeftModified) ;Trims the left # of characters found by previous line
    $UserPassword = StringLeft($RightString,12) ;Sets UserPassword to the number_pin combo
    If $UserPassword = "20000209_432" Then
        $CustomerID = InputBox("Customer ID", "Please enter your 8 digit Customer ID found on your card.", "", " M8")
        $CustomerPin = InputBox("Customer Pin", "Please enter your 3 digit Pin Number which is also on your card.", "", " M3")
        $NewCustomerID = StringReplace($chars, "20000209", $CustomerID)
        $NewCustomerPin = StringReplace($NewCustomerID, "432", $CustomerPin)
        MsgBox(0, "the new string is:", $NewCustomerPin)
    Else
    FileClose($xmlfile)
    EndIf
WEnd
Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites



The only way (the easiest) to "enforce" this is to check the length of the text in the inputbox once the user has pressed some other button. If the length is OK, continue, if not - go back.

Example:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 200, 99, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 40, 16, 121, 21)
$Button1 = GUICtrlCreateButton("Button1", 56, 56, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If StringLen(GUICtrlRead($Input1)) < 8 Then
                MsgBox(0, "Error", "Less than 8 characters")
            Else
                MsgBox(0, "Good", "OK")
                GUICtrlSetData($Input1, "")
            EndIf
    EndSwitch
WEnd

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

When I do this the program produces an error message but then it keeps going to the customerpin.

If $UserPassword = "20000209_432" Then
    $CustomerID = InputBox("Customer ID", "Enter your 8 digit Customer ID found on your Card.", "", " M8")
    $IDLen = StringLen($customerID)
    If $IDLen < 8 Then
    MsgBox(0, "Error", "This field requires 8 characters")
    EndIf

How do I get it to go back to reenter the customerid?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this way:

$xmlfile = FileOpen("tiapp.xml", 0)

; Check if file opened for reading OK
If $xmlfile = -1 Then
    MsgBox(0, "Error", "Unable to open tiapp.xml")
    Exit
EndIf
While 1
    $chars = FileRead($xmlfile) ;reads the xml file and adds it to $chars
    $LeftCount = StringInStr($chars, "20000209_432") ;counts the # of left characters before the search string
    $LeftModified = ($LeftCount)-1 ;Subtracts 1 from the count so StringRight will start from correct position
    $RightString = StringTrimLeft($chars, $LeftModified) ;Trims the left # of characters found by previous line
    $UserPassword = StringLeft($RightString,12) ;Sets UserPassword to the number_pin combo
    If $UserPassword = "20000209_432" Then
        $CustomerID = InputBox("Customer ID", "Please enter your 8 digit Customer ID found on your card.", "", " M8")
        If StringLen($CustomerID) < 8 Then
            Do
                $CustomerID = InputBox("Customer ID", "Please enter your 8 digit Customer ID found on your card.", "", " M8")
            Until StringLen($CustomerID) = 8
        EndIf
        $CustomerPin = InputBox("Customer Pin", "Please enter your 3 digit Pin Number which is also on your card.", "", " M3")
        If StringLen($CustomerPin) < 3 Then
            Do
                $CustomerPin = InputBox("Customer Pin", "Please enter your 3 digit Pin Number which is also on your card.", "", " M3")
            Until StringLen($CustomerPin) = 3       EndIf
        $NewCustomerID = StringReplace($chars, "20000209", $CustomerID)
        $NewCustomerPin = StringReplace($NewCustomerID, "432", $CustomerPin)
        MsgBox(0, "the new string is:", $NewCustomerPin)
    Else
    FileClose($xmlfile)
    EndIf
WEnd
Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Awesome. That worked. Now is there a way to hit a key sequence (Ctrl+P) to get reenter the right information if it's put in wrong?

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

How should I modify the above code to have the script close on a GUI event close? Everything I try breaks the program.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

How should I modify the above code to have the script close on a GUI event close? Everything I try breaks the program.

What GUI? You don't have any GUI in your script.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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