Jump to content
stealth

[SOLVED] Enable Checkbox only when another check box is checked

Recommended Posts

stealth

I've read the help file, but can't find a solution.

How to enable a (disabled) checkbox only when another checkbox has been checked?

Once "Cats?" checkbox has been checked, I want the Label "Number of Cats" to be enabled and allow numeric-only input of Input Box $InputCatNo

After inputting a number and pressing the Go button, I want to run notepad and send the inputted number to notepad. Thank you in advance for advice or pointing me to a help file.

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

Global $InputCatNo, $InputCatNo2
While 1
    _Animal()
    Run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    Send($InputCatNo2)
ExitLoop
WEnd

Func _Animal()
$aAnimal = GUICreate("Animals", 342, 273, 509, 166)

$CBcCats = GUICtrlCreateCheckbox("Cats?", 115, 25, 97, 25)
GUICtrlSetFont(-1, 16, 400, 0, "Calibri")
$LblCat=GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
GUICtrlSetFont(-1, 12, 400, 0, "Calibri")
        GUICtrlSetstate($LblCat,$GUI_DISABLE)
$InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
    GUICtrlSetstate($InputCatNo,$GUI_DISABLE)

$BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)
GUICtrlSetFont(-1, 24, 400, 0, "Calibri")

GUISetState(@SW_SHOW)
    $msg = GUIGetMsg()

    Switch GUIGetMsg()
        Case GUICtrlRead($CBcCats) = $GUI_CHECKED
            GUICtrlSetState($LblCat,$GUI_ENABLE)
            GUICtrlSetState($InputCatNo,$GUI_ENABLE)
                If GUICtrlRead($InputCatNo) <> "" Then
                    $InputCatNo2 = GUICtrlRead($InputCatNo)
                Else
                    $InputCatNo2 = ""
                EndIf
    EndSwitch

    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $BTNGo
                ExitLoop
        EndSelect
    WEnd

    Select
        Case $msg = $BTNGo
            GUISetState(@SW_HIDE)
    EndSelect

EndFunc ;=> _Animal
Edited by stealth
Solved

Share this post


Link to post
Share on other sites
Melba23

stealth,

How to enable a (disabled) checkbox only when another checkbox has been checked?

I can only see one checkbox - but if you mean the input then something like this should work:

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

_Animal()

Func _Animal()

    $aAnimal = GUICreate("Animals", 342, 273, 509, 166)

    $CBcCats = GUICtrlCreateCheckbox("Cats?", 115, 25, 97, 25)
    $LblCat = GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
    GUICtrlSetState($LblCat, $GUI_DISABLE)
    $InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
    GUICtrlSetState($InputCatNo, $GUI_DISABLE)

    $BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)

    GUISetState(@SW_SHOW)

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($aAnimal)
                Return
            Case $BTNGo
                $iCount = GUICtrlRead($InputCatNo)
                If $iCount Then
                    MsgBox($MB_SYSTEMMODAL, "Cats required", $iCount)
                Else
                    MsgBox($MB_SYSTEMMODAL, "Oh dear", " No cats required")
                EndIf
            Case $CBcCats
                If GUICtrlRead($CBcCats) = $GUI_CHECKED Then
                    GUICtrlSetState($LblCat, $GUI_ENABLE)
                    GUICtrlSetState($InputCatNo, $GUI_ENABLE)
                Else
                    GUICtrlSetState($LblCat, $GUI_DISABLE)
                    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
                EndIf
        EndSwitch

    WEnd

EndFunc   ;==>_Animal

M23

  • Like 1

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
stealth

Thank you, Melba.

I meant  "Enable GUI only when checkbox is checked" in topic and "How to enable a (disabled) GUI only when checkbox has been checked?" as my question.

But, you pointed out where my logic was wrong. Thank you!!

Share this post


Link to post
Share on other sites
stealth

The variable $iCount only gets sent to notepad when the red X is clicked, and clicking the GO button takes no action. Why? What am I doing wrong?

I want to pass the $InputCatNo as a variable--could be $iCount or another variable. Thank you in advance!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
;#include <MsgBoxConstants.au3>
Global $iCount, $InputCatNo

While 1
    _Animal()
    Run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    Send($iCount & "{ENTER}")
ExitLoop
WEnd

Func _Animal()
$aAnimal = GUICreate("Animals", 342, 273, 509, 166)
$CBcCats = GUICtrlCreateCheckbox("Cats?", 115, 25, 97, 25)
$LblCat = GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
GUICtrlSetState($LblCat, $GUI_DISABLE)
$InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUICtrlSetState($InputCatNo, $GUI_DISABLE)
$BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)

GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($aAnimal)
            Return
        Case $BTNGo
            $iCount = GUICtrlRead($InputCatNo)
            If $iCount Then
                $iCount = $iCount
            Else
                $iCount= ""
            EndIf
        Case $CBcCats
            If GUICtrlRead($CBcCats) = $GUI_CHECKED Then
                GUICtrlSetState($LblCat, $GUI_ENABLE)
                GUICtrlSetState($InputCatNo, $GUI_ENABLE)
            Else
                GUICtrlSetState($LblCat, $GUI_DISABLE)
                GUICtrlSetState($InputCatNo, $GUI_DISABLE)
            EndIf
    EndSwitch
WEnd
EndFunc   ;==>_Animal

 

Share this post


Link to post
Share on other sites
spudw2k

Share this post


Link to post
Share on other sites
stealth

Thanks, Supdw2k. I want notepad to open and value sent only when GO is clicked. If the GUI is closed with red X, I want nothing to happen. 

Share this post


Link to post
Share on other sites
MikahS

This works for me, as you have stated you would like it to work:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
;#include <MsgBoxConstants.au3>
Global $iCount, $InputCatNo


_Animal()

Func _Animal()
    $aAnimal = GUICreate("Animals", 342, 273, 509, 166)
    $CBcCats = GUICtrlCreateCheckbox("Cats?", 115, 25, 97, 25)
    $LblCat = GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
    GUICtrlSetState($LblCat, $GUI_DISABLE)
    $InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
    $BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)

    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Return
            Case $BTNGo
                $iCount = GUICtrlRead($InputCatNo)
                If $iCount Then
                    $iCount = $iCount
                Else
                    $iCount = ""
                EndIf
                Run("notepad.exe")
                WinWaitActive("Untitled - Notepad")
                Send($iCount & "{ENTER}")
            Case $CBcCats
                If GUICtrlRead($CBcCats) = $GUI_CHECKED Then
                    GUICtrlSetState($LblCat, $GUI_ENABLE)
                    GUICtrlSetState($InputCatNo, $GUI_ENABLE)
                Else
                    GUICtrlSetState($LblCat, $GUI_DISABLE)
                    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Animal

All good? :)

Edited by MikahS
Took out GUIDelete, as $GUI_EVENT_CLOSE is the closing of the GUI anyway.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
stealth

Thank you for your suggestion, MilkahS and all--you've pointed me in the right direction! 

I have several dozen 'animals' and input boxes for count of animals and  need to pass the variables to outside the Function to do with the counts later. I got the flickering inputboxes and then found Walkillon's suggestion: https://www.autoitscript.com/forum/topic/149208-flickering-input-box/?do=findComment&comment=1062398

Next question. Say a user checks "Cats?" checkbox, inputs a number, but decides to push Red X instead of "Go"; how do I erase the number and send nothing to notepad? Something like If Red X is pressed then $iCount = ""   ?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
;#include <MsgBoxConstants.au3>

AutoItSetOption("SendKeyDelay", 50)
;Opt("SendKeyDelay", 5)


Global $iCount, $InputCatNo

While 1
    _Animal()
    Run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    If $iCount <> "" Then Send($iCount & "{ENTER}")
    ExitLoop
WEnd

Func _Animal()
    $aAnimal = GUICreate("Animals", 342, 273, 509, 166)
    $CBcCats = GUICtrlCreateCheckbox("Cats?", 115, 25, 97, 25)
    $LblCat = GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
    GUICtrlSetState($LblCat, $GUI_DISABLE)
    $InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
    $BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)

    GUISetState(@SW_SHOW)
    GUISetState()
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $BTNGo
                ExitLoop
        EndSelect
        Switch $msg
            Case $CBcCats
            If GUICtrlRead($CBcCats) = $GUI_CHECKED Then
                    GUICtrlSetState($LblCat, $GUI_ENABLE)
                    GUICtrlSetState($InputCatNo, $GUI_ENABLE)
                ElseIf GUICtrlRead($CBcCats) = $GUI_UNCHECKED Then
                    GUICtrlSetState($LblCat, $GUI_DISABLE)
                    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
                EndIf
        EndSwitch
    WEnd

    $iCount = GUICtrlRead($InputCatNo)
    If $iCount Then
        $iCount = $iCount
    Else
        $iCount = ""
    EndIf

    Select
        Case $msg = $BTNGo
            GUISetState(@SW_HIDE)
    EndSelect
EndFunc   ;==>_Animal

Share this post


Link to post
Share on other sites
MikahS

I added some comments to show what I did:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
;#include <MsgBoxConstants.au3>

AutoItSetOption("SendKeyDelay", 50)
;Opt("SendKeyDelay", 5)


Global $iCount, $InputCatNo

While 1
    _Animal()
    Run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    If $iCount <> "" Then Send($iCount & "{ENTER}")
    ExitLoop
WEnd

Func _Animal()
    $aAnimal = GUICreate("Animals", 342, 273, 509, 166)
    $CBcCats = GUICtrlCreateCheckbox("Cats?", 115, 25, 97, 25)
    $LblCat = GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
    GUICtrlSetState($LblCat, $GUI_DISABLE)
    $InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
    $BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)

    GUISetState(@SW_SHOW)
    $msg = 0
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $BTNGo
                $iCount = GUICtrlRead($InputCatNo) ; read the input
                If $iCount Then ; if we have something in the box
                    $iCount = $iCount ; set the count
                Else
                    $iCount = "" ; if there is nothing, then set $iCount to nothing
                EndIf
                ContinueLoop ; keep going in the loop
            Case $msg = $GUI_EVENT_CLOSE ; we need to make sure we are accounting for the red "x"
                $iCount = "" ; set the count to nothing, since we did not want to go
                ExitLoop ; exit the entire loop
        EndSelect
        Switch $msg
            Case $CBcCats
                If GUICtrlRead($CBcCats) = $GUI_CHECKED Then
                    GUICtrlSetState($LblCat, $GUI_ENABLE)
                    GUICtrlSetState($InputCatNo, $GUI_ENABLE)
                ElseIf GUICtrlRead($CBcCats) = $GUI_UNCHECKED Then
                    GUICtrlSetState($LblCat, $GUI_DISABLE)
                    GUICtrlSetState($InputCatNo, $GUI_DISABLE)
                EndIf
        EndSwitch
    WEnd

    Select
        Case $msg = $BTNGo
            GUISetState(@SW_HIDE)
    EndSelect
EndFunc   ;==>_Animal

Glad to help. ^_^

Edited by MikahS
comment
  • Like 1

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
stealth

Ah-ha! Thank you, All!! I think I got it (for now) ;). Assigned $vCount to not zero and Go button; $iCount to red 'x'

Here is only an label and input box that I'll build upon.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
;#include <MsgBoxConstants.au3>

AutoItSetOption("SendKeyDelay", 50)
;Opt("SendKeyDelay", 5)


Global $iCount, $InputCatNo, $vCount

While 1
    _Animal()
    Run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    If $vCount <> "" Then Send($vCount & "{ENTER}") ;send $vCount only if a number > 0 is inputted
    ExitLoop ;exit While1 Loop
WEnd

Func _Animal()
$aAnimal = GUICreate("Animals", 342, 273, 509, 166)
$LblCat = GUICtrlCreateLabel("Number of Cats", 32, 54, 113, 23, $SS_RIGHT)
$InputCatNo = GUICtrlCreateInput("", 152, 54, 137, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) ;allow only numbers to be inputted
$BTNGo = GUICtrlCreateButton("GO", 104, 176, 97, 57)

GUISetState(@SW_SHOW)
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE ; as long as red 'x' is not clicked, loop
    $msg = GUIGetMsg() ; polls GUI to see if any events have occurred
    $iCount = GUICtrlRead($InputCatNo) ; read the input
    If $iCount <> 0 Then ; if we have something in the box not zero
        $vCount = $iCount ; set $vCount to $iCount
    Else
        $iCount = "" ; if there is nothing, then set $iCount to nothing
    EndIf
    Select
        Case $msg = $BTNGo ;when GO is clicked
            GUISetState(@SW_HIDE);  hide the GUI
            ExitLoop; exit the entire loop
        Case $msg = $GUI_EVENT_CLOSE ; we need to make sure we are accounting for the red "x"
            $vCount = "" ; set the $vCount to nothing, since we did not want to go
            ExitLoop ; exit the entire loop
    EndSelect
WEnd
EndFunc   ;==>_Animal

 

Share this post


Link to post
Share on other sites
MikahS

My pleasure. ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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

  • Similar Content

    • Silas
      By Silas
      Hello everyone,
      I have a radio button ($Radio1), which I want to disable as soon as another one get's checked (Radio5). (The system fails if the radio button i'm troubling with also gets checked).
      I know how to disable him:
      If GUICtrlRead($Radio1)=1 And Not BitAND(GUICtrlGetState($Radio5), $GUI_DISABLE) Then GUICtrlSetState($Radio5, 128) But if i try to enable $Radio5 again, after $Radio1 isn't checked anymore, it fails:
      If GUICtrlRead($Radio1)=Not 1 And Not BitAND(GUICtrlGetState($Radio5), $GUI_ENABLE) Then GUICtrlSetState($Radio5, 64)  
      Anyone knows why?
    • OneSolution
      By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • rudi
      By rudi
      Hello,
       
      for some script I need to investigate the states checked/unchecked, hidden/shown, enabled/disabled to several checkbox controls.
       
      Any suggestions to this script to retrieve the information in a better way?
      ; Autoit Version 3.3.14.2 ; GuiCtrlCheckState.au3 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $CtrlW = 100 $CtrlH = 30 $GuiW = 250 $GuiH = 300 GUICreate("Test Checkbox Status", $GuiW, $GuiH) $Ctrl = GUICtrlCreateCheckbox("Checkbox", 10, 10, $CtrlW, $CtrlH) Opt("Guicoordmode", 2) $BtnDisable = GUICtrlCreateButton("Disable", -1, 10) $BtnEnable = GUICtrlCreateButton("Enable", -1, 1) $BtnHide = GUICtrlCreateButton("Hide", 10, -$CtrlH * 2 - 1) $BtnUnHide = GUICtrlCreateButton("Show (Unhide)", -1, 1) $BtnCheckChecked = GUICtrlCreateButton("IsChecked", -$CtrlW * 2 - 10, 40) $BtnCheckEnabled = GUICtrlCreateButton("IsEnabled", -1, 1) $BtnCheckHidden = GUICtrlCreateButton("IsHidden", -1, 1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $BtnDisable GUICtrlSetState($Ctrl, $gui_disable) Case $BtnEnable GUICtrlSetState($Ctrl, $GUI_Enable) Case $BtnHide GUICtrlSetState($Ctrl, $GUI_Hide) Case $BtnUnHide GUICtrlSetState($Ctrl, $GUI_show) Case $BtnCheckChecked If CheckState($Ctrl, $GUI_CHECKED) Then ConsoleWrite("Checked" & @CRLF) Else ConsoleWrite("not checked" & @CRLF) EndIf Case $BtnCheckEnabled If CheckState($Ctrl, $GUI_Enable) Then ConsoleWrite("enabled" & @CRLF) Else ConsoleWrite("disabled" & @CRLF) EndIf Case $BtnCheckHidden If CheckState($Ctrl, $GUI_Hide) Then ConsoleWrite("Hidden" & @CRLF) Else ConsoleWrite("not hidden" & @CRLF) EndIf EndSwitch WEnd Func CheckState($_CtrlID, $_State = $GUI_CHECKED) ConsoleWrite("---------------------" & @CRLF) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_State to check = ' & $_State & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_Read = GUICtrlRead($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_Read (GuiCtrlRead) = ' & $_Read & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_StateFound = GUICtrlGetState($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_StateFound (GuiCtrlGetState) = ' & $_StateFound & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console If $_StateFound = -1 Then MsgBox(48, "Control-ID not defined", "Control-ID invalid") Return False ElseIf BitAND($_StateFound, $_State) = $_State Then Return True ElseIf BitAND($_Read, $_State) = $_State Then Return True Else Return False EndIf EndFunc ;==>CheckState Regards, Rudi.
    • gillesg
      By gillesg
      Hello,
      I am struggling in merging GUITreeViewEx, Shelltristate and enhancing to handle a third state that means : some items under are selected.
      I have difficulties handling expand order and key Space (especially when node is collapsed).
      Here the zip with UDF and and example.
       
      The problem I might need some advice to handle : 
      1- When load Treeview, have a correct settings of the checkbox for a tristate tree
      2 - Handle keyboard used for walking in tree
           Chicken is checked and  Steak is unchecked
          When walking with arrow to Meat, it gets unchecked
      3 - When node is collapsed and checked thru keyboard (space)
         the middle state is possible which should not
      Here is joined an animated gif showing the 3 problems
       
      Thanks for your advices
       
       
       
       
       
       
       
       
       
       
       

      GUITreeview3Ex.zip
    • Jibberish
      By Jibberish
      Hello,
      I have used this forum to get help many times. I thought it was time to (hopefully) help others.
      I created a script that reads a text file with a list of videos, displays the videos in a GUI with checkboxes next to the names, and displays the selected videos. This will become a part of a larger script I am creating to test a video player. The tough part for me was creating the GUI and Dynamic list of videos. I had a lot of trouble finding samples to help me, but finally found one  written by Melba23. The link is in the code, so he gets credit for helping! I also have not used arrays much and they are very picky about looping through the arrays without getting the dreaded error " Array variable has incorrect number of subscripts or subscript dimension range exceeded."  However diligence paid off!
      To run this code, take the video names commented below and create a videos.txt file in your script execution directory. You can put however many video names in this list. Thus the dynamic features of the code.
      Cheers!
      Jibberish
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = @ScriptDir & "\videos.txt" ;~ Videos in videos.txt are: ;~ bbb_1080_60s.mp4 ;~ bbb_1080_60s_1.mp4 ;~ bbb_1080_60s_2.mp4 ;~ tos_4K_60s_HEVC.mp4 ;~ tos_4K_60s_HEVC_1.mp4 ;~ tos_4K_60s_HEVC_2.mp4 ;~ ;~ Additional videos can be added to this list. The functions are Dynamic. Dim $aMediaManifest Local $aArrayFile Local $aVideos Local $sVideoName Local $i ; MAIN ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) Local $iVideoCount = UBound($aArrayFile) -1 ; Get the number of videos - 1 to prevent errors _ArrayDelete($aArrayFile, 0) ;Counter just gets in the way ; Move backwards through the array deleting the blank lines For $i = $iVideoCount - 1 To 0 Step -1 If $aArrayFile[$i] = "" Then _ArrayDelete($aArrayFile, $i) EndIf Next $aVideos = DisplayVideos($aArrayFile) $iVideoCount = UBound($aArrayFile) -1 _ArrayDisplay($aVideos) ; Display the checked videos ;~ End of MAIN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; GUI to display Videos in checkboxes ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayVideos($aArrayFile) Local $iTop = -1 Local $iLeft = -1 Local $iWidth Local $iHeight = $iVideoCount * 30 Local $iL = 10 Local $iT = 10 Local $iRow = 0 Local $aVideo Local $iA = 0, $iB = 0 Local $sFill = "" $iMMCount = UBound($aArrayFile) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedVideos[$iMMCount] ; Put the Video File Names into an Array $hGUI = GUICreate("Video Checkbox", $iLeft, $iTop, $iWidth, $iHeight) GUICtrlCreateLabel("Videos", 180, $iT) $iT = $iT + 30 ; This is a great example of using arrays to create GUI check boxes or radio buttons For $i = 0 To $iMMNewCount Step 1 $sMP4Text = $aArrayFile[$i] $aGUICheckbox[$i] = GUICtrlCreateCheckbox($sMP4Text, 30, $iT) $iT += 30 Next $idClose1 = GUICtrlCreateButton("Start", $iL, $iT) GUISetState(@SW_SHOW) ; This section reads the checkboxes and puts the video names in an array in their original position ; in case this is important (as it is to me) ; This was the toughest part to code, and I found no samples online until I saw Melba23's sample here: ; https://www.autoitscript.com/forum/topic/119843-dynamic-gui-problem/#comment-832672 ; I got this working with only a little modification. THANK YOU MELBA23 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idClose1 For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aGUICheckbox[$i]) Case $GUI_CHECKED $aCheckedVideos[$i] = $aArrayFile[$i] Case $GUI_UNCHECKED EndSwitch Next ExitLoop EndSwitch WEnd GUIDelete($hGUI) Return $aCheckedVideos EndFunc ;==>DisplayVideos  
×