Jump to content
Sign in to follow this  
LurchMan

Radio Button Issue

Recommended Posts

LurchMan

Hello Everyone -

I'm working with radio buttons and I'm attempting to get the state of the button to see which one has been pressed. I have a small example script below. I cannot seem to get it to report anything different from any of the radio buttons. I have also tried using GuiCtrlRead () to no avail. Any help is appreciated!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 498, 242, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Radio1 = GUICtrlCreateRadio("Radio1", 104, 48, 113, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 104, 96, 113, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 104, 152, 113, 17)
GUICtrlCreateButton ("click me", 50, 10)
GUICtrlSetOnEvent(-1, "ClickMe")
GUISetState(@SW_SHOW)

While 1
     Sleep(100)
WEnd

Func Form1Close()
     Exit
EndFunc

Func ClickMe ()
     $State1 = GUICtrlGetState ($Radio1)
     $State2 = GUICtrlGetState ($Radio2)
     $State3 = GUICtrlGetState ($Radio3)
     ConsoleWrite($State1 & " " & $State2 & " " & $State3 & @LF)
EndFunc

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, LurchMan. GuiCtrlGetState only gets the state of the control (enabled/disabled/hidden/etc.). I think you may be looking for something like GUICtrlRead instead. Try this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 498, 242, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Radio1 = GUICtrlCreateRadio("Radio1", 104, 48, 113, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 104, 96, 113, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 104, 152, 113, 17)
GUICtrlCreateButton ("click me", 50, 10)
GUICtrlSetOnEvent(-1, "ClickMe")
GUISetState(@SW_SHOW)

While 1
     Sleep(100)
WEnd

Func Form1Close()
     Exit
EndFunc

Func ClickMe ()
Select
Case GUICtrlRead($Radio1) = 1
ConsoleWrite("Radio Button 1 is selected!")
Case GUICtrlRead($Radio2) = 1
ConsoleWrite("Radio Button 2 is selected!")
Case GUICtrlRead($Radio3) = 1
ConsoleWrite("Radio Button 3 is selected!")
EndSelect
EndFunc
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
LurchMan

I could have sworn I tried using GuiCtrlRead () but apparently not. Thanks for the help!

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

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  

×