Sign in to follow this  
Followers 0
Daniel D.

How can I "read" which radio is selected?

9 posts in this topic

I'm writing a script to install some tools. I created the GUI and three tabs - each with a radio button list (not ready yet). After choosing a tool and press "Install", a short MsgBox should appear and ask if I really want to install it. How can I read which button I chose? I tried it with the given code, but it doesn't work. I always get the following text in the MsgBox: "Install6". But it should say: "Install AdAware SE".

Another question: Do I have to "close" a group/tab (look at the comment below my groups/tabs)?

#include <GUIConstants.au3>

GUICreate ("Installer", 300, 300)

$tab=GUICtrlCreateTab (5, 5, 290, 290)

$tab0=GUICtrlCreateTabItem ("System")
GUICtrlSetState(-1,$GUI_SHOW)

GUICtrlCreateGroup ("Please choose one...", 15, 30, 270, 255)

$radio1=GUICtrlCreateRadio ("AdAware SE", 25, 50, 150, 20)
$info1=GUICtrlCreateButton ("Info", 175, 50, 40, 20)

$radio2=GUICtrlCreateRadio ("Adobe Reader", 25, 75, 150, 20)
$info2=GUICtrlCreateButton ("Info", 175, 75, 40, 20)

$radio3=GUICtrlCreateRadio ("AntiVir", 25, 100, 150, 20)
$info3=GUICtrlCreateButton ("Info", 175, 100, 40, 20)

$radio4=GUICtrlCreateRadio ("Google Earth", 25, 125, 150, 20)
$info4=GUICtrlCreateButton ("Info", 175, 125, 40, 20)

$radio5=GUICtrlCreateRadio ("IZArc", 25, 150, 150, 20)
$info5=GUICtrlCreateButton ("Info", 175, 150, 40, 20)

$install_1=GUICtrlCreateButton ("Install...", 100, 250, 100, 30)
;GUICtrlCreateGroup ("")


;-------------------------------------------------------------------------------
$tab1=GUICtrlCreateTabItem ("Internet")
;-------------------------------------------------------------------------------
$tab2=GUICtrlCreateTabItem ("Multimedia")
;-------------------------------------------------------------------------------
GUICtrlCreateTabItem ("")

GUISetState ()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $install_1
            if GUICtrlRead($radio1) = $GUI_Checked Then MsgBox(0, "", "Install" & $radio1)
    EndSelect
Wend

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm writing a script to install some tools. I created the GUI and three tabs - each with a radio button list (not ready yet). After choosing a tool and press "Install", a short MsgBox should appear and ask if I really want to install it. How can I read which button I chose? I tried it with the given code, but it doesn't work. I always get the following text in the MsgBox: "Install6". But it should say: "Install AdAware SE".

Another question: Do I have to "close" a group/tab (look at the comment below my groups/tabs)?

#include <GUIConstants.au3>

GUICreate ("Installer", 300, 300)

$tab=GUICtrlCreateTab (5, 5, 290, 290)

$tab0=GUICtrlCreateTabItem ("System")
GUICtrlSetState(-1,$GUI_SHOW)

GUICtrlCreateGroup ("Please choose one...", 15, 30, 270, 255)

$radio1=GUICtrlCreateRadio ("AdAware SE", 25, 50, 150, 20)
$info1=GUICtrlCreateButton ("Info", 175, 50, 40, 20)

$radio2=GUICtrlCreateRadio ("Adobe Reader", 25, 75, 150, 20)
$info2=GUICtrlCreateButton ("Info", 175, 75, 40, 20)

$radio3=GUICtrlCreateRadio ("AntiVir", 25, 100, 150, 20)
$info3=GUICtrlCreateButton ("Info", 175, 100, 40, 20)

$radio4=GUICtrlCreateRadio ("Google Earth", 25, 125, 150, 20)
$info4=GUICtrlCreateButton ("Info", 175, 125, 40, 20)

$radio5=GUICtrlCreateRadio ("IZArc", 25, 150, 150, 20)
$info5=GUICtrlCreateButton ("Info", 175, 150, 40, 20)

$install_1=GUICtrlCreateButton ("Install...", 100, 250, 100, 30)
;GUICtrlCreateGroup ("")
;-------------------------------------------------------------------------------
$tab1=GUICtrlCreateTabItem ("Internet")
;-------------------------------------------------------------------------------
$tab2=GUICtrlCreateTabItem ("Multimedia")
;-------------------------------------------------------------------------------
GUICtrlCreateTabItem ("")

GUISetState ()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $install_1
            if GUICtrlRead($radio1) = $GUI_Checked Then MsgBox(0, "", "Install" & $radio1)
    EndSelect
Wend
if GUICtrlRead($radio1) = $GUI_Checked Then MsgBox(0, "test", "Install " & "AdAware SE")

If you try to read the state of the button you are note going to get the text of the button radio name.

edit changed some wording

Edit - you could also use this --->>> MsgBox(0, "test read text", "Install " & GUICtrlRead($radio1, 1)) - look for advance section of GUICtrlRead

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Try this . . .

if GUICtrlRead($radio1) = $GUI_Checked Then MsgBox(0, "", "Install " & GUICtrlRead($radio1,1))

Share this post


Link to post
Share on other sites

Anything wrong with the help file example?

#include <GUIConstants.au3>
GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered

$radio1 = GUICtrlCreateRadio ("Radio 1", 10, 10, 120, 20)
$radio2 = GUICtrlCreateRadio ("Radio 2", 10, 40, 120, 20)
GUICtrlSetState ($radio2, $GUI_CHECKED)

GUISetState ()      ; will display an  dialog box with 1 checkbox

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
            MsgBox(64, 'Info:', 'You clicked the Radio 1 and it is Checked.')
        Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
            MsgBox(64, 'Info:', 'You clicked on Radio 2 and it is Checked.')
    EndSelect
Wend

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the answers!

I'll look through them to see which example I can use, because I don't need a MsgBox that tells me which radio I just clicked and I don't need it only for the first button... The "Install" button should read :lmao: which radio I clicked and add the text to the MsgBox. I don't know how to do it instead of writing a big if..else block (after I read your answers).

Another question: Do I have to "close" a group/tab (look at the comment below my groups/tabs)?

Edited by Daniel D.

Share this post


Link to post
Share on other sites

Eval works easy in a loop to id the checked control.

#include <GUIConstants.au3>

GUICreate ("Installer", 300, 300)

$tab=GUICtrlCreateTab (5, 5, 290, 290)

$tab0=GUICtrlCreateTabItem ("System")
GUICtrlSetState(-1,$GUI_SHOW)

GUICtrlCreateGroup ("Please choose one...", 15, 30, 270, 255)

$radio1=GUICtrlCreateRadio ("AdAware SE", 25, 50, 150, 20)
$info1=GUICtrlCreateButton ("Info", 175, 50, 40, 20)

$radio2=GUICtrlCreateRadio ("Adobe Reader", 25, 75, 150, 20)
$info2=GUICtrlCreateButton ("Info", 175, 75, 40, 20)

$radio3=GUICtrlCreateRadio ("AntiVir", 25, 100, 150, 20)
$info3=GUICtrlCreateButton ("Info", 175, 100, 40, 20)

$radio4=GUICtrlCreateRadio ("Google Earth", 25, 125, 150, 20)
$info4=GUICtrlCreateButton ("Info", 175, 125, 40, 20)

$radio5=GUICtrlCreateRadio ("IZArc", 25, 150, 150, 20)
$info5=GUICtrlCreateButton ("Info", 175, 150, 40, 20)

$install_1=GUICtrlCreateButton ("Install...", 100, 250, 100, 30)
;GUICtrlCreateGroup ("")


;-------------------------------------------------------------------------------
$tab1=GUICtrlCreateTabItem ("Internet")
;-------------------------------------------------------------------------------
$tab2=GUICtrlCreateTabItem ("Multimedia")
;-------------------------------------------------------------------------------
GUICtrlCreateTabItem ("")

GUISetState ()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $install_1
            For $i = 1 To 5
                $handle = Eval('radio' & $i)
                If GUICtrlRead($handle) = $GUI_CHECKED Then
                    MsgBox(0, "", "Install " & GUICtrlRead($handle, 1))
                EndIf
            Next
    EndSelect
Wend

:lmao:

Share this post


Link to post
Share on other sites

Thanks! It's a shame. The help file is so big that you can't cover all things. :lmao:

Share this post


Link to post
Share on other sites

I finally have the MsgBox with Yes/No and want to perform an action if I press "Yes", but it doesn't work! I tried GUICtrlRead to read the controlID, but it doesn't work. I tried to read the text from the buttons (commented out) -> no luck. Can anyone help me again?

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $install_1
            For $i = 1 To 20
                $handle = Eval("radio" & $i)
                If GUICtrlRead($handle) = $GUI_CHECKED Then
                    MsgBox(4, "", "Install " & GUICtrlRead($handle, 1) & "?")
                    $yes = GUICtrlRead(6)
                    If $yes = 1 Then
                        MsgBox(0, "", "Ready!")
                    EndIf
                    ;If GUICtrlRead(6, 1) Then
                    ;   MsgBox(0, "", "Ready!")
                    ;ElseIf GUICtrlRead(7, 1) Then
                    ;   MsgBox(0, "", "Not ready!")
                    ;EndIf
                EndIf
            Next
    EndSelect
Wend

Share this post


Link to post
Share on other sites

I finally found it after 1 hour of searching!

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