Gui gcontrol as a funtion Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Gui gcontrol as a funtion

17 May 2020, 00:54

I'm trying to learn how to use glabels as functions. I have a gcontrol set to a function and it is working without error when I click on the control in the gui. However, I would also like to access the function by using a keyboard shortcut but when I do so I get an error. Here is part of the code that leads to the error:

Code: Select all

Test(i="")
{
	Global

	if instr(i, "key")
	i := substr(i, 4)
	else
	i := substr(A_guicontrol, 2)
	
	Guicontrolget, c%i%
	
	if (c%i% != "")
	soundbeep
}

f1:: Test("key1")
	
There is no error message if I click on the control with the variable name c1 but using the F1 shortcut I get:
Warning: This variable has not been assigned a value.

Specifically: c (a global variable)

How to address this issue so that I don't get the error message? Thanks.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Gui gcontrol as a funtion

17 May 2020, 01:04

You could remove #Warn
ciao
toralf
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Gui gcontrol as a funtion

17 May 2020, 01:19

Thanks, but I would rather understand how to write the code so I don't get the warning.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui gcontrol as a funtion

17 May 2020, 01:24

I am unable to get that error.
Can you supply more of your code?

Code: Select all

Gui,1:+AlwaysOnTop
Gui,1:Add,DDL, vc1 gTest,Item1|ITEM2|
Gui,1:Show,
;~ Gui1()
return
GuiClose:
*ESC::
	ExitApp

;~ Gui1(){
	;~ Global
	;~ Gui,1:+AlwaysOnTop
	;~ Gui,1:Add,DDL, vc1 gTest,Item1||ITEM2|
	;~ Gui,1:Show,
;~ }

Test(i="")
{
	Global

	if instr(i, "key")
	i := substr(i, 4)
	else
	i := substr(A_guicontrol, 2)
	
	Guicontrolget, c%i%
	
	if (c%i% != ""){
		soundbeep
		ToolTip, % c1
	}
}

Numpad1:: Test("key1")
	;~ Test("key1")
	;~ return
	
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui gcontrol as a funtion

17 May 2020, 01:28

PuzzledGreatly wrote:
17 May 2020, 01:19
Thanks, but I would rather understand how to write the code so I don't get the warning.
If you are using #Warn, just declare your variables.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Gui gcontrol as a funtion

17 May 2020, 01:49

Thanks for the reply and the idea of using tooltip. I added that and got no error when clicking on the guicontrol but did with the keyboard shortcut (making 2 error messages). The c1 variable is generated in a loop and is a text control. The text control is blank when the gui is created and text is added later. I tried adding:

Code: Select all

 loop 35
c%A_index% =
To the top of my code. This removed the error message for the tooltip for the keyboard shortcut but the original error message remains.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Gui gcontrol as a funtion

17 May 2020, 01:55

Hellbent wrote:
17 May 2020, 01:28
If you are using #Warn, just declare your variables.
Thanks, the question is how.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui gcontrol as a funtion

17 May 2020, 01:55

Please supply code that I can run that gives the error.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui gcontrol as a funtion  Topic is solved

17 May 2020, 02:06

Gives a warning.

Code: Select all

#SingleInstance, Force
#Warn
return
*ESC::ExitApp

Test(i="")
{
	Global

	if instr(i, "key")
	i := substr(i, 4)
	else
	i := substr(A_guicontrol, 2)
	
	Guicontrolget, c%i%
	
	if (c%i% != ""){
		soundbeep
		ToolTip, % c%i%
	}
}

Numpad1:: Test("key1")
Gives no warning.

Code: Select all

#SingleInstance, Force
#Warn
c1 := ""
return
*ESC::ExitApp

Test(i="")
{
	Global

	if instr(i, "key")
	i := substr(i, 4)
	else
	i := substr(A_guicontrol, 2)
	
	Guicontrolget, c%i%
	
	if (c%i% != ""){
		soundbeep
		ToolTip, % c%i%
	}
}

Numpad1:: Test("key1")
Also gives no warning.

Code: Select all

#SingleInstance, Force
#Warn
Loop, 35
	c%A_Index% := ""
return
*ESC::ExitApp

Test(i="")
{
	Global

	if instr(i, "key")
	i := substr(i, 4)
	else
	i := substr(A_guicontrol, 2)
	
	Guicontrolget, c%i%
	
	if (c%i% != ""){
		soundbeep
		ToolTip, % c%i%
	}
}

Numpad1:: Test("key1")

User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Gui gcontrol as a funtion

17 May 2020, 02:44

Thank very much Hellbent for taking the time to create those examples. My

Code: Select all

Loop, 35
c%A_Index% =
didn't work but your:

Code: Select all

Loop, 35
c%A_Index% := ""
does. Since my last reply I'm been trying to create some code that was close to my original and gave an error but I couldn't. I'm still not quite sure what is happening in my real code but there is no error message now. Thanks again.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: Gui gcontrol as a funtion

17 May 2020, 04:14

Code: Select all

#NoEnv
#SingleInstance, force

Gui, Add, DDL, vDDL gFunc Choose1, 1|²|³|4
Gui, Show, w142, MyGui
Return

Func() {
	MsgBox % "func"
	}

!a::Func()
AFAICS, no problem to trigger a function with a GUI and call it using a hotkey in parallel.
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Joey5 and 247 guests