Radio bottons with ifs

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bertrand
Posts: 11
Joined: 25 Jun 2022, 22:08

Radio bottons with ifs

Post by Bertrand » 27 Sep 2022, 11:49

Hello everyone, have a good day.

Here is my code. And I can't figure it out what is wrong in the code :crazy:


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.]

User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: Radio bottons with ifs

Post by boiler » 27 Sep 2022, 12:36

:= 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.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Radio bottons with ifs

Post by flyingDman » 27 Sep 2022, 13:51

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
14.3 & 1.3.7

Bertrand
Posts: 11
Joined: 25 Jun 2022, 22:08

Re: Radio bottons with ifs

Post by Bertrand » 27 Sep 2022, 23:21

Thank you guys,

What a silly me :lol:

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.]

User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: Radio bottons with ifs

Post by boiler » 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.

Bertrand
Posts: 11
Joined: 25 Jun 2022, 22:08

Re: Radio bottons with ifs

Post by Bertrand » 28 Sep 2022, 01:04

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!

Code: Select all

Test

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Radio bottons with ifs

Post by flyingDman » 28 Sep 2022, 01:29

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
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”