Jump to content
Sign in to follow this  

multiple input validation with clear repeat inputs

Recommended Posts


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...

#cs ----------------------------------------------------------------------------
    AutoIt Version: (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

_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)
        Case $msg = $gui_event_close Or $msg = $x
        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])
                    SplashTextOn("ALERT!", "YEAH! You have entered something", 250, 50, -1, -1, 17)

Func WarningA($Wtype, $WTitle, $WMessage, $WID, $thenFocus = True)
    Local $result
    GUICtrlSetBkColor($WID, 0xff3300)
    $result = MsgBox($Wtype, $WTitle, $WMessage)
    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)

Func _IsFocused($hWnd, $nCID)
    Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.