Page 1 of 1
Radio bottons with ifs
Posted: 27 Sep 2022, 11:49
by Bertrand
Hello everyone, have a good day.
Here is my code. And I can't figure it out what is wrong in the code
Any help will be appreciate
Code: Select all
Gui, Add, Radio, x20 vRadio11, First
Gui, Add, Radio, x+10 vRadio12, Second
Gui, Add, Radio, x+10 vRadio13, Third
Gui, Show
T::
if (Radio11:=1)
{
Msgbox, test11
return
}
if (Radio12:=1)
{
Msgbox, test12
return
}
if (Radio13:=1)
{
Msgbox, test13
return
}
thanks
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Re: Radio bottons with ifs
Posted: 27 Sep 2022, 12:36
by boiler
:= is the assignment operator. You need to use
= for comparisons. And you need to first populate the variables with what the GUI reflects using
Gui, Submit with optional
, NoHide.
Re: Radio bottons with ifs
Posted: 27 Sep 2022, 13:51
by flyingDman
Also, typically you do not need a variable for each radio button, just the first one:
Code: Select all
Gui, Add, Radio, x20 vRadio11, First
Gui, Add, Radio, x+10 , Second
Gui, Add, Radio, x+10 , Third
Gui, Show
T::
gui, submit, nohide
msgbox % Radio11
return
Re: Radio bottons with ifs
Posted: 27 Sep 2022, 23:21
by Bertrand
Thank you guys,
What a silly me
I think I need a variable for each radio button, bcuz I want save&load check on the button
Code: Select all
IniRead, Radio11, test.ini, CatalogRadio, R11
IniRead, Radio12, test.ini, CatalogRadio, R12
IniRead, Radio13, test.ini, CatalogRadio, R13
GuiControl,, Radio11,1
GuiControl,, Radio12,1
GuiControl,, Radio13,1
Gui, Add, Radio, x20 vRadio11, First
Gui, Add, Radio, x+10 vRadio12, Second
Gui, Add, Radio, x+10 vRadio13, Third
Gui, Show
T::
gui, submit, nohide
if Radio11=1
msgbox, 1
if Radio12=1
msgbox, 2
if Radio13=1
msgbox, 3
return
S::
Gui, Submit, NoHide
IniWrite, %Radio11%, test.ini, CatalogRadio, R11
IniWrite, %Radio12%, test.ini, CatalogRadio, R12
IniWrite, %Radio13%, test.ini, CatalogRadio, R13
reload
Sadly I failed load that. But I will skim more
Have a nice day
Kim
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Re: Radio bottons with ifs
Posted: 28 Sep 2022, 00:06
by boiler
It doesn’t make sense to use GuiControl before you’ve created those GUI controls. Move those statements after the GUI creation commands,
Also, please use the code tags around your code so we don’t have to do it for you as indicated at the bottom of your posts.
Re: Radio bottons with ifs
Posted: 28 Sep 2022, 01:04
by Bertrand
boiler wrote: ↑28 Sep 2022, 00:06
It doesn’t make sense to use GuiControl before you’ve created those GUI controls. Move those statements after the GUI creation commands,
Also, please use the code tags around your code so we don’t have to do it for you as indicated at the bottom of your posts.
Oh sorry, thank you!
Re: Radio bottons with ifs
Posted: 28 Sep 2022, 01:29
by flyingDman
Bertrand wrote: ↑27 Sep 2022, 23:21
I think I need a variable for each radio button, bcuz I want save&load check on the button
You do not have to:
Code: Select all
IniRead, item, radiotest.ini, CatalogRadio, R11, 2
arr:=[]
loop, 3
arr[a_index] := (a_index = item) ? 1 : 0
Gui, Add, Radio, % "x20 vRadio checked" arr.1, First
Gui, Add, Radio, % "x+10 checked" arr.2, Second
Gui, Add, Radio, % "x+10 checked" arr.3, Third
Gui, Show
return
t::
gui, submit, nohide
msgbox % Radio
return
guiclose:
gui, submit
IniWrite, %Radio%, radiotest.ini, CatalogRadio, R11
return
or, better:
Code: Select all
IniRead, item, radiotest.ini, CatalogRadio, R11, 2
arr:=[0,0,0], arr.insertat(item,1)
Gui, Add, Radio, % "x20 vRadio checked" arr.1, First
Gui, Add, Radio, % "x+10 checked" arr.2, Second
Gui, Add, Radio, % "x+10 checked" arr.3, Third
Gui, Show
return
t::
gui, submit, nohide
msgbox % Radio
return
guiclose:
gui, submit
IniWrite, %Radio%, radiotest.ini, CatalogRadio, R11
return