I am starting out using AutoIt. Here is a simple form with username and password. I want to check if information entered is valid once user clicks a button.
My problem now is that it only validates once. E.g.: if I type 5 character username, it will complain it is not 7 character (good). But once I correct that mistake and press the button again it will still say the same thing.
Do I need to have a loop?
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)
$main = GUICreate("Test Tool", 600, 600)
$hyourlabel = GUICtrlCreateLabel("YOUR CREDENTIALS", 30, 10, 256)
GUICtrlSetFont($hyourlabel, Default, 600)
Local $adminfrejalabel = GUICtrlCreateLabel("Username:", 8, 38, 64, 17)
Global $adminfrejaid = GUICtrlCreateInput("", 80, 38, 110, 17)
Local $adminpasswordlabel = GUICtrlCreateLabel("Password:", 8, 62, 64, 17)
Global $adminpassword = GUICtrlCreateInput("", 80, 62, 110, 17, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
$userButton_Check = GUICtrlCreateButton("VALIDATE", 32, 480, 85, 25)
GUICtrlSetOnEvent($userButton_Check, "startvalidation")
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitGUI")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func startvalidation()
;CHECK VALIDATIONS
$adminfrejaid = GUICtrlRead($adminfrejaid)
$adminpassword = GUICtrlRead($adminpassword)
If StringLen($adminfrejaid) <> '7' Then
MsgBox($MB_SYSTEMMODAL, "User ID", "Please enter exactly 7 characters.")
;Exit
EndIf
If StringLen($adminpassword) < '5' Then
MsgBox($MB_SYSTEMMODAL, "Your Password", "Please enter a valid password.")
;Exit
EndIf
EndFunc
Func ExitGui ()
Exit ; Exit the program
EndFunc