Help with Radio buttons

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Help with Radio buttons

05 Oct 2016, 10:12

Hey,

Ive got this script and I I want to have msgbox when I choose "Add" (alone!) and then click on "Go".
however, I can get it working on the all other radio buttons, expect when "Add" button is chosen alone.
by clicking it now its just doing nothing!

Thanks in advance!

Code: Select all

#SingleInstance force
#NoEnv
SetWorkingDir %A_ScriptDir%

Gui Show, w363 h367, WSP Deployment
Gui Add, GroupBox, x22 y73 w110 h65, What to do?
Gui Add, Radio, x32 y90 w90 h20 vRadio1 gSub1, Add
Gui Add, Radio, x32 y110 w90 h20 vRadio2 gSub2, Update
Gui Add, GroupBox, x142 y73 w120 h65 ,Deploy To:
Gui Add, Radio, x152 y90 w100 h20 vCheck1 Disabled, Web Application
Gui Add, Radio, x152 y110 w105 h20 vCheck2 Disabled, Globally Deployed
Gui Add, Button, x280 y160 w65 h45 vCheck4 gAdd Disabled, Go
return

Sub1:
GuiControlGet, Radio1
If Radio1 = 1
GuiControl, Enable, Check1
GuiControl, Enable, Check2
GuiControl, Enable, Check4
Return

Sub2:
GuiControlGet, Radio2
If Radio2 = 1
GuiControl, , Check3
GuiControl, Disable, sub1
GuiControl, Disable, Check1
GuiControl, Disable, Check2
GuiControl, Enable, Check4
Return

Add:
Gui, Submit ,NoHide
if Radio2 = 1
{
msgbox, you chose Update
return
}
else
if Check1 = 1
{
msgbox, you chose Web Application
return
}
else
if Check2 = 1
{
msgbox, you chose Globally Deployed
return
}


Last edited by Tomer on 06 Oct 2016, 01:45, edited 1 time in total.
ahkForWork
Posts: 92
Joined: 28 Mar 2016, 07:59

Re: Help with Radio buttons

05 Oct 2016, 12:02

You don't have a statement for the Radio1 radio button in your 'Add' subroutine. Add the below to it.

Code: Select all

if Radio1 = 1
{
msgbox, you chose Add
return
}
see below for better structured code. i've consolidated the 2 subroutines into one.

Code: Select all

#SingleInstance force
#NoEnv
SetWorkingDir %A_ScriptDir%

Gui Show, w363 h367, WSP Deployment
Gui Add, GroupBox, x22 y73 w110 h65, What to do?
Gui Add, Radio, x32 y90 w90 h20 vRadio1 gSub, Add
Gui Add, Radio, x32 y110 w90 h20 vRadio2 gSub, Update
Gui Add, GroupBox, x142 y73 w120 h65 ,Deploy To:
Gui Add, Radio, x152 y90 w100 h20 vCheck1 Disabled, Web Application
Gui Add, Radio, x152 y110 w105 h20 vCheck2 Disabled, Globally Deployed
Gui Add, Button, x280 y160 w65 h45 vCheck4 gAdd Disabled, Go
return

Sub:
{
Gui Submit, NoHide
if (Radio1 = 1) {
	GuiControl, Enable, Check1
	GuiControl, Enable, Check2
	GuiControl, Enable, Check4
} else if (Radio2 = 1) {
	GuiControl,, Check3 ;what does this do? as of right now, nothing.
	GuiControl Disable, sub1
	GuiControl Disable, Check1
	GuiControl Disable, Check2
	GuiControl Enable, Check4
}
return
}

;~ Sub2:
;~ {
;~ Gui Submit, NoHide
;~ if (Radio2 = 1) {
	;~ GuiControl,, Check3 ;what does this do? as of right now, nothing.
	;~ GuiControl Disable, sub1
	;~ GuiControl Disable, Check1
	;~ GuiControl Disable, Check2
	;~ GuiControl Enable, Check4
;~ }
;~ return
;~ }

Add:
{
Gui Submit, NoHide
if (Radio2 = 1) {
	msgbox, you chose Update
	return
} else if (Radio1 = 1) {
	msgbox, you chose Add
	return
}

if (Check1 = 1) {
	msgbox, you chose Web Application
	return
} else if (Check2 = 1) {
	msgbox, you chose Globally Deployed
	return
}
return
}

User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with Radio buttons

05 Oct 2016, 16:17

I didnt use statement for radio1 coz i cant get it work, even your script not working well. If you choose the other radio buttons you still get the same msg that "Add" gets :(
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Help with Radio buttons

05 Oct 2016, 17:24

I am working off of ahkForWork's consolidated script. Please, tell us exactly the problem. Cause I get different message boxes between Add and Update. Give us the exact words in the box.

If I click Add then click Go, I get one message box. That is "you chose Add".
If I click Update then click Go, I get one message box. That is "you chose Update".

If I click Add, then select Web Application, then click Go, I get one message box. That is "you chose Add".
If I click Add, then select Globally Deployed, then click Go, I get one message box. That is "you chose Add".

If I click Update while Globally Deployed is selected, the latter is grayed out. Then I click Go and I get one message box. That is "you chose Update".
If I click Update while Web Application is selected, the latter is grayed out. Then I click Go and I get one message box. That is "you chose Update".

This is to be expected, as a return is associated with either MsgBox for when if (Radio2 = 1) and else if (Radio1 = 1), so the if statements checking for Check1 and Check2's values do not execute. And either Radio1 or Radio2 has to have a value of 1 to even click the Go button - both can't be 0 at the same time to advanced past this check. Now if we drop the returns from each of those, that should be fine.
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with Radio buttons

06 Oct 2016, 01:00

Exaskryz wrote:I am working off of ahkForWork's consolidated script. Please, tell us exactly the problem. Cause I get different message boxes between Add and Update. Give us the exact words in the box.

If I click Add then click Go, I get one message box. That is "you chose Add".
If I click Update then click Go, I get one message box. That is "you chose Update".
That's good!
If I click Add, then select Web Application, then click Go, I get one message box. That is "you chose Add".
If I click Add, then select Globally Deployed, then click Go, I get one message box. That is "you chose Add".
that's Exactly the problem I cant figure out: I should have other msg for "Web Application" & Globally Deployed...

If I click Update while Globally Deployed is selected, the latter is grayed out. Then I click Go and I get one message box. That is "you chose Update".
If I click Update while Web Application is selected, the latter is grayed out. Then I click Go and I get one message box. That is "you chose Update".

This is to be expected, as a return is associated with either MsgBox for when if (Radio2 = 1) and else if (Radio1 = 1), so the if statements checking for Check1 and Check2's values do not execute. And either Radio1 or Radio2 has to have a value of 1 to even click the Go button - both can't be 0 at the same time to advanced past this check. Now if we drop the returns from each of those, that should be fine.
any sample code ?
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with Radio buttons

06 Oct 2016, 03:34

I managed to do it that way and it works,
(I uncheck the "Add" button if Web Application button is selected)

but still I guess there is must be a better way!

Code: Select all

#SingleInstance force
#NoEnv
SetWorkingDir %A_ScriptDir%

Gui Show, w363 h367, WSP Deployment
Gui Add, GroupBox, x22 y73 w110 h65, What to do?
Gui Add, Checkbox, x32 y90 w90 h20 vRadio1 gSub, Add
Gui Add, Checkbox, x32 y110 w90 h20 vRadio2 gSub, Update
Gui Add, GroupBox, x142 y73 w120 h65 ,Deploy To:
Gui Add, Radio, x152 y90 w100 h20 vCheck1 Disabled, Web Application
Gui Add, Radio, x152 y110 w105 h20 vCheck2 Disabled, Globally Deployed
Gui Add, Button, x280 y160 w65 h45 vCheck4 gAdd Disabled, Go
return



Sub:
{
Gui Submit, NoHide
if (Radio1 = 1) {
	GuiControl, Enable, Check1
	GuiControl, Enable, Check2
	GuiControl, Enable, Check4
	Control, Check,, Button5
	Control, UnCheck,, Button2
	
	} else if (Radio2 = 1) {
	GuiControl,, Check3 ;what does this do? as of right now, nothing.
	GuiControl Disable, sub1
	GuiControl Disable, Check1
	GuiControl Disable, Check2
	GuiControl Enable, Check4
}
return
}

;~ Sub2:
;~ {
;~ Gui Submit, NoHide
;~ if (Radio2 = 1) {
	;~ GuiControl,, Check3 ;what does this do? as of right now, nothing.
	;~ GuiControl Disable, sub1
	;~ GuiControl Disable, Check1
	;~ GuiControl Disable, Check2
	;~ GuiControl Enable, Check4
;~ }
;~ return
;~ }

Add:
{
Gui Submit, NoHide
if (Radio2 = 1) {
	msgbox, you chose Update
	return
} else if (Radio1 = 1) {
	msgbox, you chose Add
	return
}

if (Check1 = 1) {
	msgbox, you chose Web Application
	return
} else if (Check2 = 1) {
	msgbox, you chose Globally Deployed
	return
}
return
}


ahkForWork
Posts: 92
Joined: 28 Mar 2016, 07:59

Re: Help with Radio buttons

06 Oct 2016, 06:11

if you want to see if the 'Check' radio buttons are also pressed, remove the 'return' from under all the msgboxs in the 'Add' subroutine.
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with Radio buttons

06 Oct 2016, 07:34

ahkForWork wrote:if you want to see if the 'Check' radio buttons are also pressed, remove the 'return' from under all the msgboxs in the 'Add' subroutine.

like this:

Code: Select all

#SingleInstance force
#NoEnv
SetWorkingDir %A_ScriptDir%

Gui Show, w363 h367, WSP Deployment
Gui Add, GroupBox, x22 y73 w110 h65, What to do?
Gui Add, Radio, x32 y90 w90 h20 vRadio1 gSub, Add
Gui Add, Radio, x32 y110 w90 h20 vRadio2 gSub, Update
Gui Add, GroupBox, x142 y73 w120 h65 ,Deploy To:
Gui Add, Radio, x152 y90 w100 h20 vCheck1 Disabled, Web Application
Gui Add, Radio, x152 y110 w105 h20 vCheck2 Disabled, Globally Deployed
Gui Add, Button, x280 y160 w65 h45 vCheck4 gAdd Disabled, Go
return

Sub:
{
Gui Submit, NoHide
if (Radio1 = 1) {
	GuiControl, Enable, Check1
	GuiControl, Enable, Check2
	GuiControl, Enable, Check4
} else if (Radio2 = 1) {
	GuiControl,, Check3 ;what does this do? as of right now, nothing.
	GuiControl Disable, sub1
	GuiControl Disable, Check1
	GuiControl Disable, Check2
	GuiControl Enable, Check4
}
return
}

;~ Sub2:
;~ {
;~ Gui Submit, NoHide
;~ if (Radio2 = 1) {
	;~ GuiControl,, Check3 ;what does this do? as of right now, nothing.
	;~ GuiControl Disable, sub1
	;~ GuiControl Disable, Check1
	;~ GuiControl Disable, Check2
	;~ GuiControl Enable, Check4
;~ }
;~ return
;~ }

Add:
{
Gui Submit, NoHide
if (Radio2 = 1) {
	msgbox, you chose Update
	
} else if (Radio1 = 1) {
	msgbox, you chose Add
	
}

if (Check1 = 1) {
	msgbox, you chose Web Application
	
} else if (Check2 = 1) {
	msgbox, you chose Globally Deployed
	
}
return
}


but still, then I got 2 popup msgs when I check "Web Application",
I'd like to have only 1 msg for "Add" radio button and only 1 msg for "Web Application" radio button, etc..

Thanks!
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Help with Radio buttons

06 Oct 2016, 12:32

If you want only one message box for the Add button, you can put a return with it's block.

Code: Select all

} else if (Radio1 = 1) {
	msgbox, you chose Add
return	
}
Same with the Web Application

Code: Select all

if (Check1 = 1) {
	msgbox, you chose Web Application
return	
}
But you'd leave the other two alone. (Though just run through the if/else logic and see if you even allow a user to select a certain combination. My suspicion is because Web Application is supposed to require "Add" be selected, you'll never see the message box for Web Application (or Global Deployment)... So then you wonder, what's the point in checking?)

Return to “Ask For Help”

Who is online

Users browsing this forum: aurelius, Bing [Bot], EddyUMS, Hackerxd, magnus, mikeyww, Sabestian Caine, tatagi and 28 guests