Jump to content

Recommended Posts

Posted

Given the following GUI part:

$Group1 = GUICtrlCreateGroup("Direction of label", 320, 216, 257, 73)
$radDirectionHorizontal = GUICtrlCreateRadio("Horizontal", 328, 240, 113, 17)
$radDirectionVertical = GUICtrlCreateRadio("Vertical", 328, 264, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)

 

.. can I ask the group somehow (perhaps using a UDF) which radio button is selected ?

Something like

$selectedRadio = _RadioGroupGetSelected($Group1)

.. and have index value returned (here, 1 or 2 as last item is checked)

Or do I have to manually loop over each radioctrl ?

Btw: application is for generation of labels in a layout program.

  Reveal hidden contents

I am just a hobby programmer, and nothing great to publish right now.

  • Moderators
Posted

Myicq,

As you have only the 2 radios, all you need to do is check if one of them is checked - because if it is not then the other must be. ;)

If GUICtrlRead($radDirectionHorizontal) = 1 Then
    $selectedRadio = 1 ; it is checked
Else
    $selectedRadio = 2 ; the other is checked
EndIf

Any help? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Well, that is true.

And I have to remember to always make sure to give illustrative and complete examples ;)

It does not have to be just 2, this is obvious. But if I have 4, 6 or more the "if" codes can be pretty elaborate.

Sorry for posting such obvious example. And thank you for help so far, anyway.

  Reveal hidden contents

I am just a hobby programmer, and nothing great to publish right now.

Posted

If you put the control IDs into an array, you can loop through the array to see which one is checked.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Use an array to store the controlids and the enumerate through the array.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Moderators
  • Solution
Posted

Myicq,

I have lost count of the number of times I have asked people to give a FULL explanation of their problem so that we do not waste time offering solutions which do not match the actual state of affairs! :mad2:

This example shows 2 ways of getting the checked radio from a larger group: ;)

#include <GUIConstantsEx.au3>

Global $aRadio[5]

$hGUI = GUICreate("Test", 500, 500)

GUIStartGroup()
For $i = 0 To 4
    $aRadio[$i] = GUICtrlCreateRadio(" Radio " & $i, 10, 10 + (20 * $i), 100, 20)
Next
GUICtrlSetState($aRadio[Random(0, 4, 1)], $GUI_CHECKED)

$cButton = GUICtrlCreateButton("Read", 10, 200, 80, 30)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            For $i = 0 To 4
                If GUICtrlRead($aRadio[$i]) = 1 Then
                    ConsoleWrite("Radio " & $i & " selected" & @CRLF)
                    ExitLoop
                EndIf
            Next
        Case Else
            For $i = 0 To 4
                If $iMsg = $aRadio[$i] Then
                    ConsoleWrite("Radio " & $i & " selected" & @CRLF)
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

I hope that helps. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 5/29/2013 at 12:50 PM, Myicq said:

Well, that is true.

And I have to remember to always make sure to give illustrative and complete examples ;)

Posting 'runnable' code is a huge help, which hopefully you can understand.  9 times out of 10 when we say "do this and that" the response is "show me!" It's a lot less time consuming to add to what you have, instead of starting from scratch. Which Melba23 had to do on this occasion.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Melba,

thank you so much! I should have known better, I face same problem with customer from time to time.

Credits to you and guiness for helping out!  I will make sure to learn lesson and post better code.

  Reveal hidden contents

I am just a hobby programmer, and nothing great to publish right now.

Posted

No harm done.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
×
×
  • Create New...