Jump to content

Help with checking state of two GUI controls


HockeyFan
 Share

Recommended Posts

Help!

I'm attempting to check the status of two GUI controls to determine if the OK Button is to be enabled or not. So far it's not working. :)

What I want to do is test the status of the InputBox and the Checkbox...if the InputBox is NOT "blank", or the CheckBox is "Checked"; enable the "OK" button. If the InputBox is NOT blank, the OK button is enabled. If the CheckBox is enabled, the OK button can be enabled and the InputBox is then disabled. Also, if the CheckBox is "unchecked", the InputBox is "enabled", but if the InputBox is "Blank" the OK button is not enabled until text is entered into the InputBox.

Clear as mud, right? :o

The problem so far is that I am not getting the OK buttun to enable if I check the CheckBox. I know this is because of the IF statement checking the status of the InputBox when it is blank.

How can this be coded to work the way I want it to?

Here is what I have so far...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name:  (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000);Red
$UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$UserNameLabel2 = GUICtrlCreateLabel("( Example:  John Doe )", 12, 85, 364, 17)
$NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000ff);Blue
$TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xffff00);Yellow
GUICtrlCreateGroup("", -99, -99, 1, 1)
$UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
If GUICtrlRead ($UserNameInput) = "" Then GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE)
If GUICtrlRead ($UserNameInput) <> "" Then GUICtrlSetState ($UserNameOKButton, $GUI_ENABLE) 
Sleep(40); Idle around
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $TempVolCheckbox
   If BitAND(GUICtrlRead($TempVolCheckbox), $GUI_CHECKED) = $GUI_CHECKED Then
    GUICtrlSetState ($UserNameInput, $GUI_DISABLE)
    GUICtrlSetState ($UserNameOKButton, $GUI_ENABLE)
   Else
    GUICtrlSetState ($UserNameInput, $GUI_ENABLE) 
   EndIf
EndSwitch
WEnd
Edited by HockeyFan
Link to comment
Share on other sites

Just a matter of making sure your logic triggers the way you want. Here's one way to do it-

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name:  (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000);Red
$UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$UserNameLabel2 = GUICtrlCreateLabel("( Example:  John Doe )", 12, 85, 364, 17)
$NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000ff);Blue
$TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xffff00);Yellow
GUICtrlCreateGroup("", -99, -99, 1, 1)
$UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    Sleep(50)
    if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit
    if GUICtrlRead($TempVolCheckbox)=1 Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
    else
        GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
    endif
    if GUICtrlRead($UserNameInput)<>"" Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
    else 
        if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
    EndIf
WEnd
Link to comment
Share on other sites

It's not?

Erhm...gimme a sec to get AutoIt and test it out...It looked to good to me~

Edit:

I didn't disable the input, (I hope that's what you meant valuater)

use this for the loop-

While 1
    Sleep(50)
    if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit
    if GUICtrlRead($TempVolCheckbox)=1 Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
        GUICtrlSetState($UserNameInput,$GUI_DISABLE)
    else
        GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
        GUICtrlSetState($UserNameInput,$GUI_ENABLE)
    endif
    if GUICtrlRead($UserNameInput)<>"" Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
    else 
        if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
    EndIf
WEnd

That's all I got I think...

Edited by evilertoaster
Link to comment
Share on other sites

Just a matter of making sure your logic triggers the way you want. Here's one way to do it-

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name:  (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000);Red
$UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$UserNameLabel2 = GUICtrlCreateLabel("( Example:  John Doe )", 12, 85, 364, 17)
$NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000ff);Blue
$TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xffff00);Yellow
GUICtrlCreateGroup("", -99, -99, 1, 1)
$UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    Sleep(50)
    if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit
    if GUICtrlRead($TempVolCheckbox)=1 Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
    else
        GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
    endif
    if GUICtrlRead($UserNameInput)<>"" Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
    else 
        if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
    EndIf
WEnd
Thanks...I'll give a try!
Link to comment
Share on other sites

It's not?

Erhm...gimme a sec to get AutoIt and test it out...It looked to good to me~

Edit:

I didn't disable the input, (I hope that's what you meant valuater)

use this for the loop-

While 1
    Sleep(50)
    if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit
    if GUICtrlRead($TempVolCheckbox)=1 Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
        GUICtrlSetState($UserNameInput,$GUI_DISABLE)
    else
        GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
        GUICtrlSetState($UserNameInput,$GUI_ENABLE)
    endif
    if GUICtrlRead($UserNameInput)<>"" Then 
        GUICtrlSetState($UserNameOKButton,$GUI_ENABLE)
    else 
        if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE)
    EndIf
WEnd

That's all I got I think...

That's it!! :)

Thank you so much!

Link to comment
Share on other sites

Man, I should have never started on this one...

I worked my but off trying to get it ( just a Hobbyist .. lol )

THIS WILL ALLOW YOU TO USE THE LOOP TO GET A MESSAGE

... AND HELPS TO STOP FLICKERING!!! :)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Dim $Enable = 0

$UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))
$UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name:  (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000);Red
$UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$UserNameLabel2 = GUICtrlCreateLabel("( Example:  John Doe )", 12, 85, 364, 17)
$NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000ff);Blue
$TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xffff00);Yellow
GUICtrlCreateGroup("", -99, -99, 1, 1)
$UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetState($UserNameOKButton, $GUI_DISABLE)
GUISetState(@SW_SHOW)

AdlibEnable("Test_Input", 200)

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $UserNameOKButton
            ;AdlibDisable()
            MsgBox(4096, "Test", "OK...   ", 3)
    EndSwitch
WEnd

Func Test_Input()
    Local $checked = BitAND(GUICtrlRead($TempVolCheckbox), $GUI_CHECKED) = $GUI_CHECKED
    If GUICtrlRead($UserNameInput) = "" Then
        If $Enable = 0 And $checked Then
            GUICtrlSetState($UserNameInput, $GUI_DISABLE)
            GUICtrlSetState($UserNameOKButton, $GUI_ENABLE)
            $Enable = 1
        ElseIf $Enable = 1 And Not $checked Then
            GUICtrlSetState($TempVolCheckbox, $GUI_ENABLE)
            GUICtrlSetState($UserNameInput, $GUI_ENABLE)
            GUICtrlSetState($UserNameOKButton, $GUI_DISABLE)
            $Enable = 0
        EndIf
    Else
        If $Enable = 0 Then
            GUICtrlSetState($TempVolCheckbox, $GUI_UNCHECKED)
            GUICtrlSetState($TempVolCheckbox, $GUI_DISABLE)
            GUICtrlSetState($UserNameOKButton, $GUI_ENABLE)
            $Enable = 1
        EndIf
    EndIf
EndFunc   ;==>Test_Input

8)

Edited by Valuater

NEWHeader1.png

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