Sign in to follow this  
Followers 0
Fossil Rock

Trouble with RadioButton and CheckBoxes

7 posts in this topic

Is there something wrong with this code? It's supposed to turn off the 8 checkboxes when the radio button is checked and then if any of the checkboxes is checked it turns off the radio button.

Func _Check_State()
    If GUICtrlRead($Radio8) = 1 Then
        GUICtrlSetState($Checkbox1, $GUI_CHECKED)
        GUICtrlSetState($Checkbox2, $GUI_CHECKED)
        GUICtrlSetState($Checkbox3, $GUI_CHECKED)
        GUICtrlSetState($Checkbox4, $GUI_CHECKED)
        GUICtrlSetState($Checkbox5, $GUI_CHECKED)
        GUICtrlSetState($Checkbox6, $GUI_CHECKED)
        GUICtrlSetState($Checkbox7, $GUI_CHECKED)
        GUICtrlSetState($Checkbox8, $GUI_CHECKED)
        
        If GUICtrlRead($Checkbox1) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox2) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox3) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox4) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox5) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox6) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox7) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        If GUICtrlRead($Checkbox8) = 1 then GUICtrlSetState($Radio8, $GUI_UNCHECKED)
    EndIf
EndFunc;==<_Check_State

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites



in the upper portion of the function you are "unchecking" all of the checkboxes... then in the second portion you are checking to see if the checkboxes are "checked"

reverse the sections

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I tried that and it didn't work either.

I've also tried this too and it doesn't work.

Func _Check_State()
    Select
        Case GUICtrlRead($Radio8) = $GUI_CHECKED
            GUICtrlSetState($Checkbox1, $GUI_CHECKED)
            GUICtrlSetState($Checkbox2, $GUI_CHECKED)
            GUICtrlSetState($Checkbox3, $GUI_CHECKED)
            GUICtrlSetState($Checkbox4, $GUI_CHECKED)
            GUICtrlSetState($Checkbox5, $GUI_CHECKED)
            GUICtrlSetState($Checkbox6, $GUI_CHECKED)
            GUICtrlSetState($Checkbox7, $GUI_CHECKED)
            GUICtrlSetState($Checkbox8, $GUI_CHECKED)
        Case GUICtrlRead($Checkbox1) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox2) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox3) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox4) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox5) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox6) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox7) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
        Case GUICtrlRead($Checkbox8) = $GUI_CHECKED
            GUICtrlSetState($Radio8, $GUI_UNCHECKED)
    EndSelect
EndFunc;==<_Check_State

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this worked for me... just used array for checkboxes... you dont need to... just that this works

#include "GUIConstants.au3"
$top = 50
Dim $Checkbox[9]

GUICreate("my GUI")
$Radio8 = GUICtrlCreateRadio("radio8", 50, 20, 80, 20)
For $x = 1 To 8
    
    $Checkbox[$x] = GUICtrlCreateCheckbox( "Number " & $x, 20, $top, 80, 20)
    $top = $top + 40
Next
GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    
    If $msg = $Radio8 Then
        If GUICtrlRead($Radio8) = 1 Then
            GUICtrlSetState($Checkbox[1], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[2], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[3], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[4], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[5], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[6], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[7], $GUI_UNCHECKED)
            GUICtrlSetState($Checkbox[8], $GUI_UNCHECKED)
        EndIf
    EndIf
    
    For $t = 1 To 8
        If $msg = $Checkbox[$t] Then
            If GUICtrlRead($Checkbox[$t]) = $GUI_CHECKED Then
                GUICtrlSetState($Radio8, $GUI_UNCHECKED)
            EndIf
        EndIf
    Next
    
WEnd

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

When I do this it returns 4. What does that mean?

$State = GUICtrlRead($Checkbox1)
MsgBox(0,"",$State)

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

I found an error in my logic. It should be...

a) If the Radio button is checked then the 8 check boxes should be unchecked.

B) If any # of the checkboxes are checked the radio button is unchecked.

c) If all the check boxes are checked then it sets to a).


Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

Just remember, if you're checking the state, 1=checked, 4=unchecked

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  
Followers 0