gseller Posted May 11, 2008 Share Posted May 11, 2008 This helps me emensley! I needed validation of one or more inputs and wanted to be able to add the clear/repeat inputs function. Check this out! Special thanks to martin for his help... expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.11.10 (beta) Author: gseller Script Function: Template AutoIt script. Special Thanks to martin! Trying to get validation of multiple inputs. I would like to have validation of prefilled inputs so I can setup the click to clear input. Any help would be much apreciated. #ce ---------------------------------------------------------------------------- #include <guiconstants.au3> ;Global Const $SS_ETCHEDFRAME = 18 Global $valid1 = 0 Global $Defaultdata1 = "Text Here" Global $valid2 = 0 Global $Defaultdata2 = "Text Here" Global $NonActiveColor = 0x989898 #include<Misc.au3> _Singleton("Filename", 0) $main = GUICreate("test GUI", 300, 130,300,300) GUISetFont(11, 600) GUICtrlCreateLabel(" This is A Validating GUI", 10, 05, 200) $initialtext = "Text Here" Dim $inps[10] $inps[0] = GUICtrlCreateInput($Defaultdata1, 95, 25, 100, 20) GUICtrlSetColor(-1, $NonActiveColor) $inps[1] = GUICtrlCreateInput($Defaultdata2, 95, 50, 100, 20) GUICtrlSetColor(-1, $NonActiveColor) $Label1 = GUICtrlCreateLabel("Test1", 50, 25, 30, 20) $Label2 = GUICtrlCreateLabel("Test2", 50, 50, 30, 20) $Validate_Button = GUICtrlCreateButton("<-Validate", 205, 25, 80, 30) $go = GUICtrlCreateButton("About", 10, 80, 80, 30) $x = GUICtrlCreateButton("exit", 210, 80, 80, 30) GUISetState(@SW_SHOW, $main) $hWnd = WinGetHandle(WinGetTitle("")) While 1 _CheckInput($main, $inps[0], "Text Here", $Defaultdata1, $valid1) _CheckInput($main, $inps[1], "Text Here", $Defaultdata2, $valid2) $msg = GUIGetMsg($main) Select Case $msg = $gui_event_close Or $msg = $x Exit Case $msg = $Validate_Button For $n = 0 To 1;for the number of inputs If GUICtrlRead($inps[$n]) = $initialtext Then WarningA(0, "ERROR", "You must enter some text here!", $inps[$n]) ExitLoop Else SplashTextOn("ALERT!", "YEAH! You have entered something", 250, 50, -1, -1, 17) Sleep(2000) SplashOff() EndIf Next EndSelect WEnd Func WarningA($Wtype, $WTitle, $WMessage, $WID, $thenFocus = True) Local $result GUICtrlSetBkColor($WID, 0xff3300) $result = MsgBox($Wtype, $WTitle, $WMessage) Sleep(1000) GUICtrlSetBkColor($WID, 0xffffff) If $thenFocus Then GUICtrlSetState($WID, $GUI_FOCUS) Return $result EndFunc ;==>WarningA Func _CheckInput($hWnd, $ID, $InputDefText, ByRef $DefaultInputData, ByRef $Mark) If $Mark = 0 And _IsFocused($hWnd, $ID) And $DefaultInputData = $InputDefText Then $Mark = 1 GUICtrlSetData($ID, "") GUICtrlSetColor($ID, 0x000000) $DefaultInputData = "" ElseIf $Mark = 1 And Not _IsFocused($hWnd, $ID) And $DefaultInputData = "" And GUICtrlRead($ID) = "" Then $Mark = 0 $DefaultInputData = $InputDefText GUICtrlSetData($ID, $DefaultInputData) GUICtrlSetColor($ID, $NonActiveColor) EndIf EndFunc Func _IsFocused($hWnd, $nCID) Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd)) EndFunc 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