GUI, how to add Radio as variable? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

GUI, how to add Radio as variable?

Post by Krd » 03 Oct 2022, 06:56

Hey!

Code: Select all

Gui, Color, 808000      
Gui, Font, s12
Gui, Add, Text        ,      , Chose a number:
Gui, Add, Radio,      v1n , 1 
Gui, Add, Radio,      v2n  , 2
Gui, Add, Radio,      v3n  , 3
Gui, Add, Text        ,      , text
Gui, Add, Radio,      vat , A 
Gui, Add, Radio,      vbt  , B
Gui, Add, Radio,      vct  , C
Gui,Add,Button,gStart wp,Start
Gui, Show,, Test



Start:
Gui,Submit,Nohide 
NumberVar := Choosen number from Radio????
TextVar := Choosen text from Radio?????
MsgBox, Hallo Number %NumberVar% and Text %TextVar%
return
Whitout having to make 3*3 conditions how to I make the choosen radio bottuons two global variables?

Thanks in advance

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: GUI, how to add Radio as variable?  Topic is solved

Post by mikeyww » 03 Oct 2022, 07:35

Code: Select all

Gui, Color, 808000
Gui, Font, s12
Gui, Add, Text,, Choose a number:
For each, number in num := [2, 3, 5]
 Gui, Add, Radio, % each = 1 ? "vn" : "", %number%
Gui, Add, Text,, Text
For each, letter in let := ["A", "B", "C"]
 Gui, Add, Radio, % each = 1 ? "vl" : "", %letter%
Gui, Add, Button, w230 y+20 Default, Start
Gui, Show,, Test
Return

ButtonStart:
Gui, Submit
MsgBox, 64, Selections, % "Number: " num[n] "`n`nLetter: " let[l]
Return
Explained: Radio button
The radio button's associated output variable (if any) receives the number 1 for "on" and 0 for "off". However, if only one button in a radio group has a variable, that variable will instead receive the number of the currently selected button: 1 is the first radio button (according to original creation order), 2 is the second, and so on. If there is no button selected, 0 is stored.

just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI, how to add Radio as variable?

Post by just me » 04 Oct 2022, 03:32

As an option:

Code: Select all

#NoEnv
Gui, Color, 808000
Gui, Font, s12
Gui, Add, Text,              , Choose a number:
Gui, Add, Radio,  gNumber vN1, 1
Gui, Add, Radio,  gNumber vN2, 2
Gui, Add, Radio,  gNumber vN3, 3
Gui, Add, Text,              , Choose a text:
Gui, Add, Radio,  gLetter vT1, A
Gui, Add, Radio,  gLetter vT2, B
Gui, Add, Radio,  gLetter vT3, C
Gui, Add, Button, gStart     , Start
Gui, Show,, Test
Return

GuiClose:
ExitApp

Number:
GuiControlGet, NumberVar, , %A_GuiControl%, Text
Return

Letter:
GuiControlGet, TextVar, , %A_GuiControl%, Text
Return

Start:
MsgBox, Hallo Number "%NumberVar%" and Text "%TextVar%"
Return

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: GUI, how to add Radio as variable?

Post by Krd » 04 Oct 2022, 08:46

Both work!

Many thanks :bravo:

Post Reply

Return to “Ask for Help (v1)”