Jump to content
Sign in to follow this  
Syed23

Doubt on GUI

Recommended Posts

Syed23

Hi All,

I have one quick question on getting the event notification on GUI. Let me explain what i am asking, i have 3 label and 3 Input box on my GUI. when i put my cursor on the 2nd Input box i have to call the function which will validate the first input box data. so for that i need to know how can we do that? any suggestion ? i serached on help file but i was unable to find.. sorry for poor searching skill :graduated:


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
Melba23

Syed23,

Perhaps something like this? :graduated:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Global $ahInput[3][2]

$hGUI = GUICreate("Test", 500, 500)

For $i = 0 To 2
    GUICtrlCreateLabel("Input " & $i + 1, 10, 10 + (50 * $i), 200, 20)
    $ahInput[$i][0] = GUICtrlCreateInput("", 10, 30 + (50 * $i), 200, 20)
    $ahInput[$i][1] = GUICtrlGetHandle(-1)
Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Get handle of focuded item
    $hFocus = _WinAPI_GetFocus()
    For $i = 1 To 2
        ; Is it one of the inputs?
        If $hFocus = $ahInput[$i][1] Then
            ; Check the previous input
            If GUICtrlRead($ahInput[$i - 1][0]) = "" Then
                ; Reset to the previous input
                MsgBox(0, "Error", "Please enter a value in Input " & $i)
                GUICtrlSetState($ahInput[$i - 1][0], $GUI_FOCUS)
            EndIf
            ExitLoop
        EndIf
    Next
    
WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Syed23

The Exitloop kills my GUI completely.

Here is my script

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <AD.au3>
#include <DateTimeConstants.au3>
#include <WinAPI.au3>
Global $username, $UserID,$adObj_displayName
 
$Form1 = GUICreate("LAB Maintenence", 488, 332, 253, 127)
GUISetIcon("C:\Program Files\AutoIt3\Aut2Exe\Icons\sitemap.ico")
$Label1 = GUICtrlCreateLabel("Laptop Model", 32, 40, 95, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Combo1 = GUICtrlCreateCombo("6910P", 184, 40, 129, 25)
GUICtrlSetData(-1, "2530P|2540P|2560P|2710P|2730P|2740P|2760P|6910P|6930P|8440P|8460P|8510P|8530P|8540W|NC6000|NC6220|NC6400")
$Label2 = GUICtrlCreateLabel("Machine Account", 32, 86, 121, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Input1 = GUICtrlCreateInput("", 184, 88, 129, 21)
$Label3 = GUICtrlCreateLabel("Given To", 32, 132, 96, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Input2 = GUICtrlCreateInput("", 184, 136, 129, 21)
$Label4 = GUICtrlCreateLabel("Given By", 32, 178, 64, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Combo2 = GUICtrlCreateCombo("", 184, 184, 129, 25)
GUICtrlSetData(-1, "CM, Raghavendra|Ganesan, Karthikeyan|Garg, NiteshKumar|Mohan, Rajesh|NC, Muralikrishnan|Padmanaban, Balaji")
$Label5 = GUICtrlCreateLabel("Authorised By", 32, 232, 64, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Input3 = GUICtrlCreateInput("", 184, 232, 129, 21)
$get = GUICtrlGetHandle($Input3)
;$Button1 = GUICtrlCreateButton("::::", 320, 232, 19, 21, $WS_GROUP)
$Label6 = GUICtrlCreateLabel("Given Date", 32, 280, 77, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$MonthCal1 = GUICtrlCreateDate("", 184, 280, 129, 21, $DTS_SHORTDATEFORMAT)
$Group1 = GUICtrlCreateGroup("", 16, 16, 350, 300)
$Button2 = GUICtrlCreateButton("SUBMIT", 384, 80, 73, 57, $WS_GROUP)
GUISetState(@SW_SHOW)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ; Get handle of focuded item
    $hFocus = _WinAPI_GetFocus()
        If $hFocus = $get Then
            ; Check the previous input
            If GUICtrlRead($Input2) = "" Then
                ; Reset to the previous input
                MsgBox(0, "Error", "Please enter a value in Input " )
                GUICtrlSetState($Input2, $GUI_FOCUS)
   Else
    validation()
    GUICtrlSetData($Input2,$adObj_displayName)
            EndIf
            ExitLoop
        EndIf
 
WEnd
Func validation()
_AD_Open()
$UserID = GUICtrlRead($Input2)
$userexist = _AD_ObjectExists($UserID)
$adObj_displayName = _AD_GetObjectProperties($UserID, "displayName")
If $adObj_displayName = 0 Then
  MsgBox(16, "Debug", "The given QID is Invalid")
  GUICtrlSetState($Wrong, $GUI_SHOW)
  ;_ExtMsgBox(16, "&OK", " User ID - Error", 'UserID ' & ' (' & StringUpper($UserID) & ') ' & ' does not exist is Active Directory')
  ;Exit
Else
  $adObj_displayName = $adObj_displayName[1][1]
  $UserID = $adObj_displayName
EndIf
_AD_Close()
Return $adObj_displayName
 
EndFunc   ;==>validation

any sugesstion ?

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
Melba23

Syed23,

any sugesstion ?

Several, but I will restrain myself! :)

My code needed an ExitLoop because it ran in a For..Next loop. Your code does not and so the ExitLoop is breaking out of the While...WEnd loop and ending your script - just remove it. ;)

You might perhaps have tried that yourself before posting, by the way. :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Syed23

:graduated: i could have commented that too.. i have tried by removing the ExitLoop. But what happen is the loop continues... i mean the loop is infinite and it continues the execution i couldn't able to stop ;)

Note:

even i tried the return value as true on success and if i get the return value as True i set exitloop... doesn't work..... why my mind is not working to the basic level too :)


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
Melba23

Syed23,

Of course your loop is infinite - the only way you exit the loop at present is to hit the [X] of the GUI. :)

You need to define another event based on your inputs - what is $Button2 = GUICtrlCreateButton("SUBMIT"...) supposed to do? :graduated:

Actioning that would give you a way to exit the loop and continue with your script. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Syed23

Hi Melba23,

I am happy that finally my brain worked somewhat :graduated: i fixed that problem by using below code.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <AD.au3>
#include <DateTimeConstants.au3>
#include <WinAPI.au3>
Global $username, $UserID,$adObj_displayName,$hFocus,$t = 0

$Form1 = GUICreate("LAB Maintenence", 488, 332, 253, 127)
GUISetIcon("C:\Program Files\AutoIt3\Aut2Exe\Icons\sitemap.ico")
$Label1 = GUICtrlCreateLabel("Laptop Model", 32, 40, 95, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Combo1 = GUICtrlCreateCombo("6910P", 184, 40, 129, 25)
GUICtrlSetData(-1, "2530P|2540P|2560P|2710P|2730P|2740P|2760P|6910P|6930P|8440P|8460P|8510P|8530P|8540W|NC6000|NC6220|NC6400")
$Label2 = GUICtrlCreateLabel("Machine Account", 32, 86, 121, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Input1 = GUICtrlCreateInput("", 184, 88, 129, 21)
$Label3 = GUICtrlCreateLabel("Given To", 32, 132, 96, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Input2 = GUICtrlCreateInput("Enter your QID", 184, 136, 129, 21)
$Label4 = GUICtrlCreateLabel("Given By", 32, 178, 64, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Combo2 = GUICtrlCreateCombo("", 184, 184, 129, 25)
GUICtrlSetData(-1, "CM, Raghavendra|Ganesan, Karthikeyan|Garg, NiteshKumar|Mohan, Rajesh|NC, Muralikrishnan|Padmanaban, Balaji")
$Label5 = GUICtrlCreateLabel("Authorised By", 32, 232, 64, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$Input3 = GUICtrlCreateInput("", 184, 232, 129, 21)
$get = GUICtrlGetHandle($Input3)
;$Button1 = GUICtrlCreateButton("::::", 320, 232, 19, 21, $WS_GROUP)
$Label6 = GUICtrlCreateLabel("Given Date", 32, 280, 77, 24)
GUICtrlSetFont(-1, 12, 800, 0, "Bodoni MT")
$MonthCal1 = GUICtrlCreateDate("", 184, 280, 129, 21, $DTS_SHORTDATEFORMAT)
$Group1 = GUICtrlCreateGroup("", 16, 16, 350, 300)
$Button2 = GUICtrlCreateButton("SEND", 384, 80, 73, 57, $WS_GROUP)
$Tick = GUICtrlCreatePic(@DesktopDir & "\tick.jpg", 320, 138, 16, 16)
GUICtrlSetState($Tick,$GUI_HIDE)
$Wrong = GUICtrlCreatePic(@DesktopDir & "\error.jpg", 320, 138, 16, 16)
GUICtrlSetState($Wrong, $GUI_HIDE)
GUISetState(@SW_SHOW)
;MonthCal1 = GUICtrlCreateMonthCal("2011/09/22", 176, 96, 191, 154)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ; Get handle of focuded item
    $hFocus = _WinAPI_GetFocus()
        If $hFocus = $get Then
            ; Check the previous input
            If GUICtrlRead($Input2) = ""  Then
                ; Reset to the previous input
    
    If $t < 1 Then ; <=============== This helps to get rid of the multiple error messages
                MsgBox(0, "Error", "Please enter a value in Input " )
    EndIf
                GUICtrlSetState($Input2, $GUI_FOCUS)
   ElseIf $adObj_displayName = "" Then ;<=============== This helps me to stop calling my function repeatedly.
    validation()
    If $adObj_displayName <> "" Then
     GUICtrlSetData($Input2,$adObj_displayName)
     GUICtrlSetState($Wrong, $GUI_HIDE)
     GUICtrlSetState($Tick, $GUI_SHOW)
    Else
     GUICtrlSetData($Input2,"")
    EndIf
            EndIf
   $hFocus = 0
        EndIf

WEnd
Func validation()
 $t= $t + 1
 _AD_Open()
 $UserID = GUICtrlRead($Input2)
 $userexist = _AD_ObjectExists($UserID)
 $adObj_displayName = _AD_GetObjectProperties($UserID, "displayName")
 If $adObj_displayName = 0 Then
  MsgBox(16, "Debug", "The given QID is Invalid")
  GUICtrlSetState($Wrong, $GUI_HIDE)
  GUICtrlSetState($Wrong, $GUI_SHOW)
 Else
  $adObj_displayName = $adObj_displayName[1][1]
  $UserID = $adObj_displayName
 EndIf
 _AD_Close()
EndFunc   ;==>validation

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

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  

×