Sign in to follow this  
Followers 0
angel666

radio behaving like checkbox

3 posts in this topic

Hi there,

This is my first post in the forum.

I have been working on some AutoIt scripts developing some tools for myself and ran into a scenario where I wanted radio controls with checkbox functionality at the same time retaining their properties. I implemented it in the following way. I do not consider myself an expert in AutoIt (casual dev searching AutoIt help and user forums whenever I need some info). This is definitely not the best way to implement. Please let me know if there's a better way. I am posting this in case someone might find it useful.

;;globals
$rad1Checked = 0
$rad2Checked = 0
$rad3Checked = 0
....
....

            While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg

            Case $RadioRad1
                $rad2Checked = 0
                $rad3Checked  = 0
                If $rad1Checked = 1 Then
                    $rad1Checked = 0
                    GUICtrlSetState ($RadioRad1, $GUI_UNCHECKED)
                ElseIf $rad1Checked = 0 Then
                    $rad1Checked = 1
                    GUICtrlSetState ($RadioRad1, $GUI_CHECKED)
                EndIf

            Case $RadioRad2
                $rad1Checked = 0
                $rad3Checked  = 0
                If $rad2Checked = 1 Then
                    $rad2Checked = 0
                    GUICtrlSetState ($RadioRad2, $GUI_UNCHECKED)
                ElseIf $rad2Checked = 0 Then
                    $rad2Checked = 1
                    GUICtrlSetState ($RadioRad2, $GUI_CHECKED)
                EndIf

            Case $RadioRad3
                $rad1Checked = 0
                $rad2Checked  = 0
                If $rad3Checked = 1 Then
                    $rad3Checked = 0
                    GUICtrlSetState ($RadioRad3, $GUI_UNCHECKED)
                ElseIf $rad3Checked = 0 Then
                    $rad3Checked = 1
                    GUICtrlSetState ($RadioRad3, $GUI_CHECKED)
                EndIf

Share this post


Link to post
Share on other sites



INCDNR (Incomplete code, did not run.)

In general though, if you find yourself repeating the exact same lines of code like that you are missing something. Here, you could use GuiOnEventMode and have just one handler function for all the radio buttons.

:huh2:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

INCDNR (Incomplete code, did not run.)

Yeah, I just posted the relevant code so it wont run as-is.

In general though, if you find yourself repeating the exact same lines of code like that you are missing something. Here, you could use GuiOnEventMode and have just one handler function for all the radio buttons.

:huh2:

I knew events was one way to go about. I am not a fan of code repetition or using globals etc (I used three in my snippet), but I just wanted to present the idea and get some feedback on if there was a better way (looks like events is probably the best way to go).

Thanks.

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