Jump to content

validation of multiple inputs


Recommended Posts

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.

edit: Added testfile

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.11.10 (beta)
 Author:         gseller

 Script Function:
 Template AutoIt script.
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

#include<Misc.au3> 
_Singleton("Filename", 0)

$main = GUICreate ("test GUI", 300,130)
GUISetFont (11, 600)
GUICtrlCreateLabel (" This is A Validating GUI", 10, 05, 200)
$Input1 = GUICtrlCreateInput("Text Here",95, 25, 100, 20)
$Input2 = GUICtrlCreateInput("Text Here",95, 50, 100, 20)
$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
    $msg = GUIGetMsg ($main)
    Select
        Case $msg = $gui_event_close Or $msg = $x 
            Exit
  Case $msg = $Validate_Button
        if guictrlread($Input1) > "" then 
        SplashTextOn( "ALERT!", "YEAH! You have entered something" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
  ElseIf guictrlread($Input1) = "Text Here" then 
        SplashTextOn( "ALERT!", "You still have Text Here" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
        Else
        SplashTextOn( "ALERT!", "PLEASE ENTER SOMETHING" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
   EndIf
            if guictrlread($Input2) > "" then 
        SplashTextOn( "ALERT!", "YEAH! You have entered something" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
   ElseIf guictrlread($Input2) = "Text Here" then 
        SplashTextOn( "ALERT!", "You still have Text Here" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
        Else
        SplashTextOn( "ALERT!", "PLEASE ENTER SOMETHING" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
  EndIf
    EndSelect
WEnd
Edited by gesller
Link to comment
Share on other sites

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.

edit: Added testfile

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.11.10 (beta)
 Author:         gseller

 Script Function:
 Template AutoIt script.
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

#include<Misc.au3> 
_Singleton("Filename", 0)

$main = GUICreate ("test GUI", 300,130)
GUISetFont (11, 600)
GUICtrlCreateLabel (" This is A Validating GUI", 10, 05, 200)
$Input1 = GUICtrlCreateInput("Text Here",95, 25, 100, 20)
$Input2 = GUICtrlCreateInput("Text Here",95, 50, 100, 20)
$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
    $msg = GUIGetMsg ($main)
    Select
        Case $msg = $gui_event_close Or $msg = $x 
            Exit
  Case $msg = $Validate_Button
        if guictrlread($Input1) > "" then 
        SplashTextOn( "ALERT!", "YEAH! You have entered something" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
  ElseIf guictrlread($Input1) = "Text Here" then 
        SplashTextOn( "ALERT!", "You still have Text Here" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
        Else
        SplashTextOn( "ALERT!", "PLEASE ENTER SOMETHING" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
   EndIf
            if guictrlread($Input2) > "" then 
        SplashTextOn( "ALERT!", "YEAH! You have entered something" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
   ElseIf guictrlread($Input2) = "Text Here" then 
        SplashTextOn( "ALERT!", "You still have Text Here" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
        Else
        SplashTextOn( "ALERT!", "PLEASE ENTER SOMETHING" , 250, 50, -1, -1,17 )
         Sleep(2000)
         SplashOff()
  EndIf
    EndSelect
WEnd
Maybe something like this-

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.11.10 (beta)
    Author:      gseller
    
    Script Function:
    Template AutoIt script.
    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

#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<-*"
Dim $inps[10]
$inps[0] = GUICtrlCreateInput($initialtext, 95, 25, 100, 20)
$inps[1] = GUICtrlCreateInput($initialtext, 95, 50, 100, 20)
$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
    $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
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This seems to work very well.. I will be posting this in the examples.. Thank You martin!

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.11.10 (beta)
    Author:         gseller
    
    Script Function:
    Template AutoIt script.
    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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...