My Gui works except the NO button! Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pepper Potato
Posts: 8
Joined: 22 Jun 2021, 06:08

My Gui works except the NO button!

22 Jun 2021, 06:34

This GUI is slightly odd- there is a text_to_speech function to help partially blind people. And it works fine with the WinWaitClose command. And it correctly returns the data if you click YES/OK.

However the "NO" button doesn't work- clicking "NO" seems to run the YES script. :oops:

Code: Select all

RETURN_YES_OR_NO(text)
	{global TheText, FirstName, LastName, OK, NO
	
	GuiHWND = WinExist()           ;--get handle to this gui..
	Gui, +LastFound
		
	Gui, Font, s18
	Gui, Add , Button, Default x0 y40 gNO, NO
	Gui, Add , Edit  , vFirstName x+0 y40 w150,
	Gui, Add , Edit  , vLastName x+0 y40 w150,
	Gui, Add , Button, Default x+0 y40 gOK, OK
	Gui, Font, s20
	Gui, Add, edit, +wrap w900 x0 y+20 vTheText, %text%
	gui, show, , TITLE !!
	text_to_speech(text)	

	WinWaitClose
		
	OK:
	GuiControlGet, Return_vFirstName, , FirstName
	GuiControlGet, Return_vLastName, , LastName
	if (Return_vFirstName="" && Return_vLastName="")
		{msgbox, enter SOME data! 
		return
		}
	else if (Return_vFirstName="")
		{msgbox, enter FIRST Name!
		return
		}
	else
		{GuiControlGet, ReturnText, , TheText
		Gui, Destroy
		returncode:=Return_vFirstName . " ## " . Return_vLastName . " ## " . ReturnText
		return, returncode
		}
	return
	
	NO:
		Gui, Destroy
		return, "no"
	return
	
	GuiEscape:
		Gui, Destroy
		return, "no"
	return
	}
[Mod edit: [code][/code] tags added.]

What am I doing wrong? :cry: :cry: :cry:

If it's unclear what my goal is, here's instructions:
1. You're given data (%text%), & you have a chance to modify it.
2. If the data is nonsense you click "NO".
3. If the data is good you can enter a FirstName & LastName (but GUI will not allow you to continue if the FirstName is blank.)
Pepper Potato
Posts: 8
Joined: 22 Jun 2021, 06:08

Re: My Gui works except the NO button!

22 Jun 2021, 08:55

Update: I found a solution but it's not standard.

(I just ignore the buttons and check the return values.)

eg:

Code: Select all

GuiControlGet, Return_vFirstName, , FirstName
GuiControlGet, Return_vLastName, , LastName
if (Return_vFirstName="")
	return, "no"
else	if (Return_vLastName="")
	msgbox, ENTER LAST NAME.
[Mod edit: [code][/code] tags added.]

It seems to be working perfectly.

And I see some errors, eg I did not need a "return" after "msgbox, ENTER LAST NAME."
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: My Gui works except the NO button!  Topic is solved

22 Jun 2021, 09:38

It looks like you posted while I had this page open. I'll post this anyways as it may prove helpful.


Code: Select all

#SingleInstance, Force
;***********************************************************************************
;***********************************************************************************
Numpad1:: ToolTip, % RETURN_YES_OR_NO("Blah Blah Blah")
;***********************************************************************************
;***********************************************************************************	

RETURN_YES_OR_NO(text){
	global TheText, FirstName, LastName, OK, NO
	
	static Output 
	Output := "" ;<<<<<<<<------------------------ 
	
	GuiHWND = WinExist() ;--get handle to this gui..
	Gui, +LastFound

	Gui, Font, s18
	Gui, Add , Button, Default x0 y40 gNO, NO
	Gui, Add , Edit , vFirstName x+0 y40 w150,
	Gui, Add , Edit , vLastName x+0 y40 w150,
	Gui, Add , Button, Default x+0 y40 gOK, OK
	Gui, Font, s20
	Gui, Add, edit, +wrap w900 x0 y+20 vTheText, %text%
	gui, show, , TITLE !!
	text_to_speech(text)

	
	WinWaitClose
	return Output ;<<<<<<<<------------------------ 
	
OK:
	GuiControlGet, Return_vFirstName, , FirstName
	GuiControlGet, Return_vLastName, , LastName
	if (Return_vFirstName="" && Return_vLastName=""){
		msgbox, enter SOME data!
	}else if(Return_vFirstName=""){
		msgbox, enter FIRST Name!
	}else{
		GuiControlGet, ReturnText, , TheText
		Output := Return_vFirstName . " ## " . Return_vLastName . " ## " . ReturnText     ;<<<<<<<<------------------------ 
		Gui, Destroy
	}
	return

GuiClose:
GuiEscape:
NO:
	Output := "No"   ;<<<<<<<<------------------------ 
	Gui, Destroy
	return
	
}

*ESC::ExitApp
Pepper Potato
Posts: 8
Joined: 22 Jun 2021, 06:08

Re: My Gui works except the NO button!

24 Jun 2021, 02:44

That works PERFECTLY ! And it's fixed properly, unlike mine. Thank you so much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Marium0505, Nerafius and 202 guests