Sign in to follow this  
Followers 0
BabyG

Which radio button is pushed?

5 posts in this topic

Hey guys

Without asking every radio button "IsChecked" is there a way to just ask which radio button is checked? Like the current selection for list/combo boxes?

Share this post


Link to post
Share on other sites



Yes, you can write your own function to do it. Post your Radio creation and I can write a function for you.

It would also help if you use a formula to create them. Like:

GUICtrlCreateCombo('',5,$ComboNumber * 20 + 10)

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Share this post


Link to post
Share on other sites

Hold on....

I didn't create the radio buttons, they are apart of another application. I didn't create the application, I just wish to automate it. Isn't GUICtrlCreateCombo used when ur creating ur own GUI? I've never used it though. Anyways, at the moment I have 3 radio buttons (in some situations 6) and to handle them I've created this function:

Func ChangeRadio( $title,ByRef $button, $value, $wait, $buttons, $button1, $button2 = "", $button3 = "", $button4 = "", $button5 = "", $button6 = "" )
    Select
        Case $buttons = 1
            If $button1 = "" then
                InvalidFuncValue ( "$button1", $button1, "ChangeRadio" )
            EndIf
            If $button2 <> "" then
                InvalidFuncValue ( "$button2", $button2, "ChangeRadio" )
            EndIf
        Case $buttons = 2
            If $button1 = "" then
                InvalidFuncValue ( "$button1", $button1, "ChangeRadio" )
            EndIf
            If $button2 = "" then
                InvalidFuncValue ( "$button2", $button2, "ChangeRadio" )
            EndIf
            If $button3 <> "" then
                InvalidFuncValue ( "$button3", $button3, "ChangeRadio" )
            EndIf
        Case $buttons = 3
            If $button1 = "" then
                InvalidFuncValue ( "$button1", $button1, "ChangeRadio" )
            EndIf
            If $button2 = "" then
                InvalidFuncValue ( "$button2", $button2, "ChangeRadio" )
            EndIf
            If $button3 = "" then
                InvalidFuncValue ( "$button3", $button3, "ChangeRadio" )
            EndIf
            If $button4 <> "" then
                InvalidFuncValue ( "$button4", $button4, "ChangeRadio" )
            EndIf
        Case $buttons = 4
            If $button1 = "" then
                InvalidFuncValue ( "$button1", $button1, "ChangeRadio" )
            EndIf
            If $button2 = "" then
                InvalidFuncValue ( "$button2", $button2, "ChangeRadio" )
            EndIf
            If $button3 = "" then
                InvalidFuncValue ( "$button3", $button3, "ChangeRadio" )
            EndIf
            If $button4 = "" then
                InvalidFuncValue ( "$button4", $button4, "ChangeRadio" )
            EndIf
            If $button5 <> "" then
                InvalidFuncValue ( "$button5", $button5, "ChangeRadio" )
            EndIf
        Case $buttons = 5
            If $button1 = "" then
                InvalidFuncValue ( "$button1", $button1, "ChangeRadio" )
            EndIf
            If $button2 = "" then
                InvalidFuncValue ( "$button2", $button2, "ChangeRadio" )
            EndIf
            If $button3 = "" then
                InvalidFuncValue ( "$button3", $button3, "ChangeRadio" )
            EndIf
            If $button4 = "" then
                InvalidFuncValue ( "$button4", $button4, "ChangeRadio" )
            EndIf
            If $button5 = "" then
                InvalidFuncValue ( "$button5", $button5, "ChangeRadio" )
            EndIf
            If $button6 <> "" then
                InvalidFuncValue ( "$button6", $button6, "ChangeRadio" )
            EndIf
        Case $buttons = 6
            If $button1 = "" then
                InvalidFuncValue ( "$button1", $button1, "ChangeRadio" )
            EndIf
            If $button2 = "" then
                InvalidFuncValue ( "$button2", $button2, "ChangeRadio" )
            EndIf
            If $button3 = "" then
                InvalidFuncValue ( "$button3", $button3, "ChangeRadio" )
            EndIf
            If $button4 = "" then
                InvalidFuncValue ( "$button4", $button4, "ChangeRadio" )
            EndIf
            If $button5 = "" then
                InvalidFuncValue ( "$button5", $button5, "ChangeRadio" )
            EndIf
            If $button6 = "" then
                InvalidFuncValue ( "$button6", $button6, "ChangeRadio" )
            EndIf
        Case Else
                InvalidFuncValue ( "$buttons", $buttons, "ChangeRadio" )
    EndSelect
    
    Select
        Case $value = 0
            $button = $button1
        Case $value = 1
            $button = $button2
        Case $value = 2
            $button = $button3
        Case $value = 3
            $button = $button4
        Case $value = 4
            $button = $button5
        Case $value = 5
            $button = $button6
        Case Else
                InvalidFuncValue ( "$value", $value, "ChangeRadio" )
    EndSelect
    
    WaitForWindow($title, $wait)
    $seconds = 0
    $currentvalue = ControlCommand ( $title, "", $button, "IsChecked", "" )
    While @error = 1
        Sleep( 250 )
        $seconds = $seconds + .25
        If $seconds >= $wait then
            ButtonNotFound( $title, $button, $wait )
            $seconds = 0
        EndIf
        $currentvalue = ControlCommand ( $title, "", $button, "IsChecked", "" )
    WEnd
    If $currentvalue <> $value then
        Click( $title, $button, $wait )
    EndIf
    return $currentvalue
EndFunc

It works and all, just a very long function to do a simple task... yea I know alot of it is error handling but that's to make sure I don't stuff it up when calling the function :lmao:. (Yes there are links to other functions I have created in it)

Anyways, just looking for an easier way... coz this way is very messy!

Thanx guys

Share this post


Link to post
Share on other sites

Why not use a For-loop?

So if you had a window and the AutoIt Spy/Info utility says the first radio button is "Button4" and the last button is "Button9" you would use:

$currentValue = getCheckedRadio("Windowtitle...", "", 4, 9)

Func getCheckedRadio($title, $text, $startNumer, $endNumber)
   Local $i
   For $i = $startNumber to $endNumber
      If ControlCommand($title, $text, "Button" & $i, "IsChecked") Then Return "Button" & $i
   Next
   SetError(1);only set error if don't find and return a checked button
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Yep...

That's what I'd do at the moment. Other then that I just thought there might be a function that handle a 'group' of radio buttons. So for example if a radio button was ever added to the program I wouldn't have to change my code (well i might but not the part that asks which radio buttons is choosen). So if one time there where 2 radio buttons and the last one was selected it would return 1 (if using 0 base)... and if 3 radio buttons came up next time and the last one was selected it would return 2. Doesn't look like there is one but.

Thanx guys :lmao:!!!

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