Sign in to follow this  
Followers 0
niubbone

Multiple Radios in Help File

5 posts in this topic

#1 ·  Posted (edited)

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $button_1, $group_1, $radio_1, $radio_2, $radio_3
    Local $radio_4, $radio_5, $radio_6, $input_1, $input_2
    Local $radioval1, $radioval2, $msg

    Opt("GUICoordMode", 1)

    GUICreate("Radio Box Grouping Demo", 400, 280)

    ; Create the controls
    $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
    $group_1 = GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
    GUIStartGroup()
    $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
    $radio_2 = GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
    $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)
    GUIStartGroup()
    $radio_4 = GUICtrlCreateRadio("Radio &A", 120, 120, 70, 20)
    $radio_5 = GUICtrlCreateRadio("Radio &B", 120, 150, 60, 20)
    $radio_6 = GUICtrlCreateRadio("Radio &C", 120, 180, 60, 20)
    GUIStartGroup()
    $input_1 = GUICtrlCreateInput("Input 1", 200, 20, 160, 30)
    $input_2 = GUICtrlCreateInput("Input 2", 200, 70, 160, 30)

    ; Set the defaults (radio buttons clicked, default button, etc)
    GUICtrlSetState($radio_1, $GUI_CHECKED)
    GUICtrlSetState($radio_6, $GUI_CHECKED)
    GUICtrlSetState($button_1, $GUI_FOCUS + $GUI_DEFBUTTON)

    ; Init our vars that we will use to keep track of radio events
    $radioval1 = 0    ; We will assume 0 = first radio button selected, 2 = last button
    $radioval2 = 2

    GUISetState()

    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control.  Both
    ; methods are equally valid
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit

            Case $msg = $button_1
                MsgBox(0, "Button", "Radio " & $radioval1 & @LF & "Radio " & Chr($radioval2 + Asc("A")) & @LF & GUICtrlRead($input_1) & @LF & GUICtrlRead($input_2))

            Case $msg = $radio_1 Or $msg = $radio_2 Or $msg = $radio_3
                $radioval1 = $msg - $radio_1

            Case $msg = $radio_4 Or $msg = $radio_5 Or $msg = $radio_6
                $radioval2 = $msg - $radio_4

        EndSelect
    WEnd
EndFunc   ;==>Example

What the hell does it do? Why a so awkard and twisted procedure to read multiple controls.... In the comments says you can also use Guictrlread(). I tried also to experiment a bit with that instead of the procedure shown in help because it was too hard to understand for me but i came up with nothing...

any help?

Down here the portion of code i don't get...

; Init our vars that we will use to keep track of radio events
    $radioval1 = 0    ; We will assume 0 = first radio button selected, 2 = last button
    $radioval2 = 2;WHAT? What are these 2 variables for and why 0 and 2 O_o

    GUISetState();in hel it says it's for making an empty dialog box.... What? i don't see it

    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control.  Both
    ; methods are equally valid
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit

            Case $msg = $button_1
                MsgBox(0, "Button", "Radio " & $radioval1 & @LF & "Radio " & Chr($radioval2 + Asc("A")) & @LF & GUICtrlRead($input_1) & @LF & GUICtrlRead($input_2));WHAT? WHAT THE HELL THIS DOES?

            Case $msg = $radio_1 Or $msg = $radio_2 Or $msg = $radio_3
                $radioval1 = $msg - $radio_1;What the hell these subtractions are for...

            Case $msg = $radio_4 Or $msg = $radio_5 Or $msg = $radio_6
                $radioval2 = $msg - $radio_4

        EndSelect
    WEnd
EndFunc   ;==>Example
Edited by niubbone

Share this post


Link to post
Share on other sites



anyone?

Share this post


Link to post
Share on other sites

I have tried to explain it by adding comments and also by running a msgbox will give an indication of what is stored in the variables.

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $button_1, $group_1, $radio_1, $radio_2, $radio_3
    Local $radio_4, $radio_5, $radio_6, $input_1, $input_2
    Local $radioval1, $radioval2, $msg

    Opt("GUICoordMode", 1)

    GUICreate("Radio Box Grouping Demo", 400, 280)

    $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
    $group_1 = GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
    GUIStartGroup()
    $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
    $radio_2 = GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
    $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)
    GUIStartGroup()
    $radio_4 = GUICtrlCreateRadio("Radio &A", 120, 120, 70, 20)
    $radio_5 = GUICtrlCreateRadio("Radio &B", 120, 150, 60, 20)
    $radio_6 = GUICtrlCreateRadio("Radio &C", 120, 180, 60, 20)
    GUIStartGroup()
    $input_1 = GUICtrlCreateInput("Input 1", 200, 20, 160, 30)
    $input_2 = GUICtrlCreateInput("Input 2", 200, 70, 160, 30)

 
    GUICtrlSetState($radio_1, $GUI_CHECKED)
    GUICtrlSetState($radio_6, $GUI_CHECKED)
    GUICtrlSetState($button_1, $GUI_FOCUS + $GUI_DEFBUTTON)

    ; the radio buttons are set as 2 groups of 3, one group containing $radio_1, $radio_2 & $radio_3 the other radio group conatianing $radio_4, $radio_5 & $radio_6.
    ; When in a group like this only one per group of the radios can be set checked.
    ; To store which radio is checked variables $radioval1 for the first group & $radioval2 for the second group have been created and using a 0 based index.
    ; for example if $radio_1 is checked $radioval1 = 0 & if $radio_2 is checked $radioval1 = 1

    $radioval1 = 0 ; store the first group as the first radio is checked ie $radio_1
    $radioval2 = 2 ; store the second group as the third radio is checked ie $radio_6

ConsoleWrite($button_1 & @CR & $radio_6 & @CR)

    GUISetState() ; Changes the state of a GUI window. with no paramaters entered will show the previously created window


    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit

            Case $msg = $button_1
                MsgBox(0, "Button", "Radio " & $radioval1 & @LF & "Radio " & Chr($radioval2 + Asc("A")) & @LF & GUICtrlRead($input_1) & @LF & GUICtrlRead($input_2))

            Case $msg = $radio_1 Or $msg = $radio_2 Or $msg = $radio_3
                $radioval1 = $msg - $radio_1 ; The vatiables $radio_1, $radio_2 & $radio_3 contain the controldId. The $msg variable contains the controlId of which control was clicked, which was set by $msg = GUIGetMsg().
    ; For instance the controlID were set as follows $radio_1 = 5, $radio_2 = 6 & $radio_3 = 7, if $radio_1 was clicked $msg - $radio_1  would be the same as ($radio_1 which = 5) - ($radio_1 which = 5) which means $radioval1 would be set to 0.
    ; If $radio_3 was clicked $msg - $radio_1  would be the same as ($radio_1 which = 5) - ($radio_3 which = 7) which means $radioval1 would be set to 2
                MsgBox(0, "", "ControlID Conatained in $msg = " & $msg & @CR & "This controlID is " & GUICtrlRead($msg, 1) & @cr & "$radioval1 = $msg - $radio_1 will be as follows" & @CR & $radioval1 & " = " & $msg & " - " & $radio_1)

            Case $msg = $radio_4 Or $msg = $radio_5 Or $msg = $radio_6
                $radioval2 = $msg - $radio_4
                MsgBox(0, "", "ControlID Conatained in $msg = " & $msg & @CR & "This controlID is " & GUICtrlRead($msg, 1) & @cr & "$radioval2 = $msg - $radio_4 will be as follows" & @CR & $radioval2 & " = " & $msg & " - " & $radio_4)
        EndSelect
    WEnd
EndFunc   ;==>Example

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

Well, Yoriz, I looked at the topic an hour ago and I think I'm slowly grasping the concept. Many thanks.

Anyway, I want to share my personal opinion with you.

Autoit is the 1st programming language i learn. (Started about 1 month and half ago)

Till now I've seen that the biggest problem I get when coding something is how autoit manages variable types. For example string and numbers are problematic to get to work togheter and so on.

But this thing of radio buttons, I must say, is the most twisted, complicated and odd way to manage such a simple thing. Maybe It's just because I still didn't grasped the concept properly (going to practice right now, as I asked because in need), but I doubt that later on my opinion will change. Very awkward to me.

Anyway really many thanks for the explanation, has been incredibly helpful, considering also that the help file about this subject, it's very poorly detailed.

Whenever you like, i would like to see other ways of managing multiple radios, also link to other posts would be appreciated.

Share this post


Link to post
Share on other sites

Here's a tip for you.

It's obvious that you have never looked at the help files for other languages. If you had you would realize that the AutoIt help file is one of the finest pieces of documentation for a programming language you will ever see.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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