Jump to content

Recommended Posts

Posted

Hey,

I'm new in the AutoIt scripting.
My first test was to make a tool with four checkboxes.
A selection between NL and FR and a second between Live and Query
When i switch NL into checked, FR has to go unchecked.
When i switch NL into uncheched, FR has to go checked.
Idem for Live and Query
When i put Live into checked, Query has to go unchecked.
This is what i have for the moment but it isn't working at all. :-/

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

...

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    Local $idChckLngNL = GUICtrlCreateCheckbox("Nederlands", 35, 10, 90, 25)
    Local $idChckLngFR = GUICtrlCreateCheckbox("Francais", 35, 30, 90, 25)
    Local $idChckLive = GUICtrlCreateCheckbox("Live DB", 155, 10, 90, 25)
    Local $idChckQry = GUICtrlCreateCheckbox("Query DB", 155, 30, 90, 25)

   If BitAND(GuiCtrlRead($idChckLngNL, $GUI_CHECKED)) = 1 Then
      GUICtrlSetState($idChckLngFR, $GUI_CHECKED)
      GUICtrlSetState($idChckLngNL, $GUI_UNCHECKED)
   ElseIf BitAND(GuiCtrlRead($idChckLngNL)) = 0 Then
      GUICtrlSetState($idChckLngFR, $GUI_UNCHECKED)
      GUICtrlSetState($idChckLngNL, $GUI_CHECKED)
   Else
      GUICtrlSetState($idChckLngNL, $GUI_UNCHECKED)
   EndIf

Thanks for helping !

  • Moderators
Posted

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted (edited)
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>

GUICreate("Test")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    Local $gLangRadBtns = GUICtrlCreateGroup("Language", 30, 10, 100, 70)
    Local $idChckLngNL = GUICtrlCreateRadio("Nederlands", 35, 25, 90, 25)
    Local $idChckLngFR = GUICtrlCreateRadio("Francais", 35, 45, 90, 25)
    Local $gLangRadBtns = GUICtrlCreateGroup("DB", 155, 10, 100, 70)
    Local $idChckLive = GUICtrlCreateRadio("Live DB", 160, 25, 90, 25)
    Local $idChckQry = GUICtrlCreateRadio("Query DB", 160, 45, 90, 25)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

;~    If (GuiCtrlRead($idChckLngNL, $GUI_CHECKED)) = 1 Then
;~       GUICtrlSetState($idChckLngFR, $GUI_CHECKED)
;~       GUICtrlSetState($idChckLngNL, $GUI_UNCHECKED)
;~    ElseIf (GuiCtrlRead($idChckLngNL)) = 0 Then
;~       GUICtrlSetState($idChckLngFR, $GUI_UNCHECKED)
;~       GUICtrlSetState($idChckLngNL, $GUI_CHECKED)
;~    Else
;~       GUICtrlSetState($idChckLngNL, $GUI_UNCHECKED)
;~    EndIf
WEnd

Anything wrong with using radio buttons and groups?

Alternatively, with checkboxes (I find radio buttons/groups easier):

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

GUICreate("Test")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    Local $gLangRadBtns = GUICtrlCreateGroup("Language", 30, 10, 100, 70)
    Local $idChckLngNL = GUICtrlCreateCheckbox("Nederlands", 35, 25, 90, 25)
    Local $idChckLngFR = GUICtrlCreateCheckbox("Francais", 35, 45, 90, 25)
    Local $gLangRadBtns = GUICtrlCreateGroup("DB", 155, 10, 100, 70)
    Local $idChckLive = GUICtrlCreateRadio("Live DB", 160, 25, 90, 25)
    Local $idChckQry = GUICtrlCreateRadio("Query DB", 160, 45, 90, 25)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $idChckLngNL                                                           ;Received change state message from NL Checkbox
            If GUICtrlRead($idChckLngNL) = $GUI_CHECKED Then    ;If check message
                GUICtrlSetState($idChckLngNL, $GUI_CHECKED)     ;Check NL box
                GUICtrlSetState($idChckLngFR, $GUI_UNCHECKED)   ;AND Uncheck FR box
            Else                                                                                    ;Any other message received from NL box (e.g. Uncheck)
                GUICtrlSetState($idChckLngNL, $GUI_UNCHECKED)   ;Uncheck the NL box, no need to change FR box state
            EndIf
        Case $idChckLngFR
            If GUICtrlRead($idChckLngFR) = $GUI_CHECKED Then    ; N.B. The BitAND isn't really necessary for this program so far.
                GUICtrlSetState($idChckLngFR, $GUI_CHECKED)
                GUICtrlSetState($idChckLngNL, $GUI_UNCHECKED)
            Else
                GUICtrlSetState($idChckLngFR, $GUI_UNCHECKED)
            EndIf
    EndSwitch
WEnd

 

Edited by Sidley
Alternate solution
Posted

@Zedna: I discovered AutoIt in march 2018 and always used the "short" way to check if a checkbox/radio control was checked/unchecked, without any issue :

If GUICtrlRead($idRadio) = $GUI_CHECKED Then

instead of :

If BitAND(GUICtrlRead($idRadio), $GUI_CHECKED) = $GUI_CHECKED Then

The help file reflects this change. Let's see what's written under "GUICtrlRead" topic, in 3 different versions of AutoIt :

Version 3.3.8.1 (2012)

For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.

Version 3.3.10.0 (2013)

For Checkbox, Radio control several states can be returned. So use i.e. BitAND(GUICtrlRead($Item), $GUI_CHECKED) to test if the control is checked.

Version 3.3.12.0 (2014) until today :

For Checkbox and Radio controls only the $GUI_CHECKED (1), $GUI_UNCHECKED (4) or $GUI_INDETERMINATE (2) states are returned so the value can be used directly.

Nostalgia... back in 2006, Valuater and SmOke_N already discussed about it :
https://www.autoitscript.com/forum/topic/22870-gui_checked-and-gui_unchecked/?do=findComment&comment=159274

Stampy (2008) or mikell (2011) quoting the old help file :
https://www.autoitscript.com/forum/topic/61823-radio-button-state-detection/?do=findComment&comment=463753
https://www.autoitscript.fr/forum/viewtopic.php?p=55997#p55997

 

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

Hey,

Thank you for the replys !

I will try the radiobuttons instead and see if i can work with them.

Comming from C# the use of checkboxes was for me an easy copy/paste.
But if the radiobutton works, meaby it's word of it to try het also in c#.

The topic can be closed for me.

Thanks again to you all

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
  • Recently Browsing   0 members

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