GuiControlGet custom function not working inside another function Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

GuiControlGet custom function not working inside another function

08 May 2019, 12:31

Hello, I do not understand why my function "©¡" does not work inside another function (focus on line 7,8,16).
-------------------------------------------------
For example this code work as expected calling the function "©¡" (line 7,16):

Code: Select all




	X:=A_ScreenWidth/2 - 16, Y:=A_ScreenHeight/2, ©(,"-Caption +AlwaysOnTop +ToolWindow +Resize","Margin: 1¦1","Font: w1 s15¦Calibri Light"
	,"Edit: w2000 h27 WantTab -E0x200 v# +HwndGw -VScroll", "Show: x" X-15 " y" Y " w17 h28"), ¡s("{Down}"), ID:=WinActive("A")
	Loop {
	©¡(,"#"), 
	;; GuiControlGet, #
	(#<>e ? (#="" ? ©(,"Show: x" X-15 " y" Y " w17 h28") : (@:=¡©¡(#,,15), ©(,"Show: x" X-(@[1]/2)-15 " y" Y " w" @[1]+14 " h28"), e:=#)) :"")
	} Until (WinActive("ahk_id " ID) && (GetKeyState("Esc") || GetKeyState("Enter") || GetKeyState("NumpadEnter")))
	Msgbox % 1
	Msgbox % ((GetKeyState("Esc") ? "" : #), ©(,"Destroy"))



©¡(ByRef a:="", ByRef b:="", ByRef c:="") {
	GuiControlGet, %b%
}



¡s(ByRef a) {
		SendInput, % a
} ©(ByRef _©:="", ByRef ©*) {
	Local c, d, e, f, g, h, i, z
	Loop, % (©.Length(), z:=(_© ? _© ": " : "")) {
	c:=©[A_Index],         d:=InStr(c,"¦¦"),   (d   ?   (e:=SubStr(c,d+2),d:=SubStr(c,1,d-1))   :   d:=c)
	, f:=InStr(d,"¦"), (f ? (g:=SubStr(d,f+1),f:=SubStr(d,1,f-1)) : f:=d),       h:=InStr(f,": "), (h ? (i:=SubStr(f,h+2),h:=SubStr(f,1,h-1)) : h:=f)
	If (h="Text" || h="Edit") {
	Gui, % z "Add", % h, % i, % g
	h:=i:=g:=""
	} Else {
	Gui, % z h, % i, % g, % e
	h:=i:=g:=e:=""
}}} ¡©¡(ByRef a, ByRef b:="Calibri Light", ByRef c:=13) {
	Gui, ¡©¡:Font, s%c%, %b%
	Gui, ¡©¡:Add, Text, R1, %a%
	GuiControlGet, d, ¡©¡:Pos, Static1
	Gui, ¡©¡:Destroy
	Return, [dW, dH]
}
But if I do the same inside another function, it stops working ("©¡": line 7,16):

Code: Select all

a_4_()

a_4_() {
	X:=A_ScreenWidth/2 - 16, Y:=A_ScreenHeight/2, ©(,"-Caption +AlwaysOnTop +ToolWindow +Resize","Margin: 1¦1","Font: w1 s15¦Calibri Light"
	,"Edit: w2000 h27 WantTab -E0x200 v# +HwndGw -VScroll", "Show: x" X-15 " y" Y " w17 h28"), ¡s("{Down}"), ID:=WinActive("A")
	Loop {
	©¡(,"#"), 
	;; GuiControlGet, #
	(#<>e ? (#="" ? ©(,"Show: x" X-15 " y" Y " w17 h28") : (@:=¡©¡(#,,15), ©(,"Show: x" X-(@[1]/2)-15 " y" Y " w" @[1]+14 " h28"), e:=#)) :"")
	} Until (WinActive("ahk_id " ID) && (GetKeyState("Esc") || GetKeyState("Enter") || GetKeyState("NumpadEnter")))
	Msgbox % 1
	Return, ((GetKeyState("Esc") ? "" : #), ©(,"Destroy"))
}


©¡(ByRef a:="", ByRef b:="", ByRef c:="") {
	GuiControlGet, %b%
}



¡s(ByRef a) {
		SendInput, % a
} ©(ByRef _©:="", ByRef ©*) {
	Local c, d, e, f, g, h, i, z
	Loop, % (©.Length(), z:=(_© ? _© ": " : "")) {
	c:=©[A_Index],         d:=InStr(c,"¦¦"),   (d   ?   (e:=SubStr(c,d+2),d:=SubStr(c,1,d-1))   :   d:=c)
	, f:=InStr(d,"¦"), (f ? (g:=SubStr(d,f+1),f:=SubStr(d,1,f-1)) : f:=d),       h:=InStr(f,": "), (h ? (i:=SubStr(f,h+2),h:=SubStr(f,1,h-1)) : h:=f)
	If (h="Text" || h="Edit") {
	Gui, % z "Add", % h, % i, % g
	h:=i:=g:=""
	} Else {
	Gui, % z h, % i, % g, % e
	h:=i:=g:=e:=""
}}} ¡©¡(ByRef a, ByRef b:="Calibri Light", ByRef c:=13) {
	Gui, ¡©¡:Font, s%c%, %b%
	Gui, ¡©¡:Add, Text, R1, %a%
	GuiControlGet, d, ¡©¡:Pos, Static1
	Gui, ¡©¡:Destroy
	Return, [dW, dH]
}
Yet, if I do the same with the "GuiControlGet" command, instead of my function, it works (line 8):

Code: Select all

a_4_()

a_4_() {
	X:=A_ScreenWidth/2 - 16, Y:=A_ScreenHeight/2, ©(,"-Caption +AlwaysOnTop +ToolWindow +Resize","Margin: 1¦1","Font: w1 s15¦Calibri Light"
	,"Edit: w2000 h27 WantTab -E0x200 v# +HwndGw -VScroll", "Show: x" X-15 " y" Y " w17 h28"), ¡s("{Down}"), ID:=WinActive("A")
	Loop {
	;; ©¡(,"#"), 
	GuiControlGet, #
	(#<>e ? (#="" ? ©(,"Show: x" X-15 " y" Y " w17 h28") : (@:=¡©¡(#,,15), ©(,"Show: x" X-(@[1]/2)-15 " y" Y " w" @[1]+14 " h28"), e:=#)) :"")
	} Until (WinActive("ahk_id " ID) && (GetKeyState("Esc") || GetKeyState("Enter") || GetKeyState("NumpadEnter")))
	Msgbox % 1
	Return, ((GetKeyState("Esc") ? "" : #), ©(,"Destroy"))
}


©¡(ByRef a:="", ByRef b:="", ByRef c:="") {
	GuiControlGet, %b%
}



¡s(ByRef a) {
		SendInput, % a
} ©(ByRef _©:="", ByRef ©*) {
	Local c, d, e, f, g, h, i, z
	Loop, % (©.Length(), z:=(_© ? _© ": " : "")) {
	c:=©[A_Index],         d:=InStr(c,"¦¦"),   (d   ?   (e:=SubStr(c,d+2),d:=SubStr(c,1,d-1))   :   d:=c)
	, f:=InStr(d,"¦"), (f ? (g:=SubStr(d,f+1),f:=SubStr(d,1,f-1)) : f:=d),       h:=InStr(f,": "), (h ? (i:=SubStr(f,h+2),h:=SubStr(f,1,h-1)) : h:=f)
	If (h="Text" || h="Edit") {
	Gui, % z "Add", % h, % i, % g
	h:=i:=g:=""
	} Else {
	Gui, % z h, % i, % g, % e
	h:=i:=g:=e:=""
}}} ¡©¡(ByRef a, ByRef b:="Calibri Light", ByRef c:=13) {
	Gui, ¡©¡:Font, s%c%, %b%
	Gui, ¡©¡:Add, Text, R1, %a%
	GuiControlGet, d, ¡©¡:Pos, Static1
	Gui, ¡©¡:Destroy
	Return, [dW, dH]
}
It's not much of a problem, but I do not understand why there are differences.
Thanks in advance,
User avatar
Maestr0
Posts: 136
Joined: 05 Dec 2013, 17:43

Re: GuiControlGet custom function not working inside another function  Topic is solved

09 May 2019, 07:45

The issue is that inside a function, only variables that are global or given are known.

This code works (note the first line of the a_4_ function)

Code: Select all

a_4_()

a_4_() {
	global ; <----
	X:=A_ScreenWidth/2 - 16, Y:=A_ScreenHeight/2, ©(,"-Caption +AlwaysOnTop +ToolWindow +Resize","Margin: 1¦1","Font: w1 s15¦Calibri Light"
	,"Edit: w2000 h27 WantTab -E0x200 v# +HwndGw -VScroll", "Show: x" X-15 " y" Y " w17 h28"), ¡s("{Down}"), ID:=WinActive("A")
	Loop {
	©¡(,"#"), 
	;; GuiControlGet, #
	(#<>e ? (#="" ? ©(,"Show: x" X-15 " y" Y " w17 h28") : (@:=¡©¡(#,,15), ©(,"Show: x" X-(@[1]/2)-15 " y" Y " w" @[1]+14 " h28"), e:=#)) :"")
	} Until (WinActive("ahk_id " ID) && (GetKeyState("Esc") || GetKeyState("Enter") || GetKeyState("NumpadEnter")))
	Msgbox % 1
	Return, ((GetKeyState("Esc") ? "" : #), ©(,"Destroy"))
}


©¡(ByRef a:="", ByRef b:="", ByRef c:="") {
	GuiControlGet, %b%
}



¡s(ByRef a) {
		SendInput, % a
} ©(ByRef _©:="", ByRef ©*) {
	Local c, d, e, f, g, h, i, z
	Loop, % (©.Length(), z:=(_© ? _© ": " : "")) {
	c:=©[A_Index],         d:=InStr(c,"¦¦"),   (d   ?   (e:=SubStr(c,d+2),d:=SubStr(c,1,d-1))   :   d:=c)
	, f:=InStr(d,"¦"), (f ? (g:=SubStr(d,f+1),f:=SubStr(d,1,f-1)) : f:=d),       h:=InStr(f,": "), (h ? (i:=SubStr(f,h+2),h:=SubStr(f,1,h-1)) : h:=f)
	If (h="Text" || h="Edit") {
	Gui, % z "Add", % h, % i, % g
	h:=i:=g:=""
	} Else {
	Gui, % z h, % i, % g, % e
	h:=i:=g:=e:=""
}}} ¡©¡(ByRef a, ByRef b:="Calibri Light", ByRef c:=13) {
	Gui, ¡©¡:Font, s%c%, %b%
	Gui, ¡©¡:Add, Text, R1, %a%
	GuiControlGet, d, ¡©¡:Pos, Static1
	Gui, ¡©¡:Destroy
	Return, [dW, dH]
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Google [Bot], madensuyu1, peter_ahk and 362 guests