Error In GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aliztori
Posts: 119
Joined: 19 Jul 2022, 12:44

Error In GUI

Post by aliztori » 14 Aug 2022, 03:30

what's problem of my code?

Code: Select all

Put(putType,item,itemType)
{	
	FaToEng()
	; This Function Select The Project panel and select file (item) and Put in timeline

	Coordmode, Pixel, Window
	Coordmode, Mouse, Window

	BlockInput, MouseMove
	BlockInput, SendAndMouse
	BlockInput, On
	
	MouseGetPos xPosCursor, yPosCursor

	Global TimelineX
	Global TimelineY
	ImageSearch, FoundX, FoundY, TimelineX, TimelineY, TimelineX+400, TimelineY+500, %A_WorkingDir%\Nest Source Sequnce OFF.png
		if ErrorLevel = 0
		{
			MouseMove, FoundX+10, FoundY+10, 0
			Click
		}	
	
	Global ProjectX
	Global ProjectY
	Global Track
	
	prFocus("Project")
	Send,^!d
	Send, ^\
	Send, +{BS}
	Sleep, 10
	Send, %item%
	Sleep, 5
	
	Loop 
		{	
			If (A_index > 10)
					Break
			ImageSearch, FoundX, FoundY, ProjectX, ProjectY, ProjectX+300, ProjectY+300, %A_WorkingDir%\%item%.png
			if ErrorLevel = 1
				ImageSearch, FoundX, FoundY, ProjectX, ProjectY, ProjectX+300,ProjectY+800, %A_WorkingDir%\%Item%.png
			if ErrorLevel = 0
				{
					MouseMove, FoundX+15, FoundY+15, 0
					Click Left
					
					Sleep,10

					If InStr(putType,"Overwrite")
						{
							If InStr(Item,"Tran")
								TimeChanger("-7")
							GoSub inja
							; GoSub CtrlGet
							Send,^/
						}
							
				
					If InStr(putType,"insertt")
						{
							Send,!{NumpadEnter}
							Send,^+/
						}
						
					; If InStr(item,"Zoom In Ease")
						; TimeChanger(-70)		
					; If InStr(item,"Zoom Out Ease")
						; TimeChanger(-60)		
					Break
				}
		}


	PutEnding:
	MouseMove, xPosCursor, yPosCursor, 0
	Blockinput, MouseMoveOff 
	BlockInput, off
	
	inja:
	Settimer, CtrlGet, 250
	Gui,Add,Edit,x5 w90 vTrack
	Gui, +AlwaysOnTop -Caption
	Gui,Show,w100 h35
	Return

	CtrlGet:
		GuiControlGet, txtVar,, Track
		If (txtVar ="1")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				Sleep,100
				If InStr(itemType,"V")
					Send,^1
				If InStr(itemType,"A")	
					Send,^7
			}
		If (txtVar ="2")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				If InStr(itemType,"V")
					Send,^2
				If InStr(itemType,"A")	
					Send,^8
			}						
		If (txtVar ="3")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				If InStr(itemType,"V")
					Send,^3
				If InStr(itemType,"A")	
					Send,^9
			}
		If (txtVar ="4")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				If InStr(itemType,"V")
					Send,^4
				If InStr(itemType,"A")	
					Send,^10
			}
		If (txtVar ="5")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				Send,^5
			}
		If (txtVar ="6")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				Send,^6
			}
		Return

}
this error:

Code: Select all

---------------------------
Keyboard Assignments.ahk
---------------------------
Error in #include file "T:\AHK\Premier Functions.Ahk":
     The same variable cannot be used for more than one control.

Specifically: vTrack

	Line#
	403: Break
	404: }
	405: }
	409: MouseMove,xPosCursor,yPosCursor,0
	410: BlockInput,MouseMoveOff
	411: BlockInput,off
	414: SetTimer,CtrlGet,250
--->	415: Gui,Add,Edit,x5 w90 vTrack
	416: Gui,+AlwaysOnTop -Caption
	417: Gui,Show,w100 h35
	418: Return
	421: GuiControlGet,txtVar,,Track
	422: if (txtVar ="1")  
	423: {
	424: SetTimer,CtrlGet,off

The current thread will exit.
---------------------------
OK   
---------------------------

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

Re: Error In GUI

Post by boiler » 14 Aug 2022, 04:06

The problem is you’re re-creating the GUI each time through the loop. Create the GUI once at the top of your script, and just keep the Gui, Show line inside the loop.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Error In GUI

Post by wetware05 » 14 Aug 2022, 04:55

We can not recreate your same type of error, because other errors jump before, because parts of the script are missing. I've already run into the same problem in my own scripts.

Two possible solutions:

1. Empty the variable in each cycle with Track:="" (This surely does not solve it, since the error mentions the name that contains the variable).

2. You have to create a numeric variable outside the Loop, for example Number:=0 and assign it to the line: Gui,Add,Edit,x5 w90 vTrack%Number%

It is very possible that later the txtVar variable will give you the same problem. You have to rename it on each line If (txtVar%Number% ="X") Somewhere you have to make the variable change with Number++ (at the beginning of each Loop) Then you have to change the line to GuiControlGet, txtVar%number%,, Track%Number% In this way such variables change their names every cycle with txtVar1, txtVar2... and blah, blah, blah.

But he knows more boiler than me, and his answer may be better. The thing is that I don't know if you have realized that everything is inside a function, and that although the gui is outside the loop, the name that contains the variable (track) will be the same in each click and therefore it will give the same error.

aliztori
Posts: 119
Joined: 19 Jul 2022, 12:44

Re: Error In GUI

Post by aliztori » 14 Aug 2022, 06:11

boiler wrote:
14 Aug 2022, 04:06
The problem is you’re re-creating the GUI each time through the loop. Create the GUI once at the top of your script, and just keep the Gui, Show line inside the loop.

Code: Select all

Put(putType,item,itemType)
{	
	FaToEng()
	; This Function Select The Project panel and select file (item) and Put in timeline

	Coordmode, Pixel, Window
	Coordmode, Mouse, Window

	BlockInput, MouseMove
	BlockInput, SendAndMouse
	BlockInput, On
	
	MouseGetPos xPosCursor, yPosCursor

	Global TimelineX
	Global TimelineY
	ImageSearch, FoundX, FoundY, TimelineX, TimelineY, TimelineX+400, TimelineY+500, %A_WorkingDir%\Nest Source Sequnce OFF.png
		if ErrorLevel = 0
		{
			MouseMove, FoundX+10, FoundY+10, 0
			Click
		}	
	
	Global ProjectX
	Global ProjectY
	Global Track
	
	prFocus("Project")
	Send,^!d
	Send, ^\
	Send, +{BS}
	Sleep, 10
	Send, %item%
	Sleep, 5
	
	Gui,Add,Edit,x5 w90 vTrack
	Gui, +AlwaysOnTop -Caption
	
	Loop 
		{	
			If (A_index > 10)
					Break
			ImageSearch, FoundX, FoundY, ProjectX, ProjectY, ProjectX+300, ProjectY+300, %A_WorkingDir%\%item%.png
			if ErrorLevel = 1
				ImageSearch, FoundX, FoundY, ProjectX, ProjectY, ProjectX+300,ProjectY+800, %A_WorkingDir%\%Item%.png
			if ErrorLevel = 0
				{
					MouseMove, FoundX+15, FoundY+15, 0
					Click Left
					
					Sleep,10

					If InStr(putType,"Overwrite")
						{
							If InStr(Item,"Tran")
								TimeChanger("-7")
							GoSub inja
							Send,^/
						}
							
				
					If InStr(putType,"insertt")
						{
							Send,!{NumpadEnter}
							Send,^+/
						}
						
					; If InStr(item,"Zoom In Ease")
						; TimeChanger(-70)		
					; If InStr(item,"Zoom Out Ease")
						; TimeChanger(-60)		
					Break
				}
		}


	PutEnding:
	MouseMove, xPosCursor, yPosCursor, 0
	Blockinput, MouseMoveOff 
	BlockInput, off
	
	inja:
	Settimer, CtrlGet, 250

	Gui,Show,w100 h35
	
	CtrlGet:
		GuiControlGet, txtVar,, Track
		If (txtVar ="1")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				Sleep,100
				If InStr(itemType,"V")
					Send,^1
				If InStr(itemType,"A")	
					Send,^7
			}
		If (txtVar ="2")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				If InStr(itemType,"V")
					Send,^2
				If InStr(itemType,"A")	
					Send,^8
			}						
		If (txtVar ="3")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				If InStr(itemType,"V")
					Send,^3
				If InStr(itemType,"A")	
					Send,^9
			}
		If (txtVar ="4")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				If InStr(itemType,"V")
					Send,^4
				If InStr(itemType,"A")	
					Send,^10
			}
		If (txtVar ="5")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				Send,^5
			}
		If (txtVar ="6")
			{
				Settimer, CtrlGet, off
				gui, Destroy
				Send,^6
			}
		Return

}
isnt work

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

Re: Error In GUI

Post by boiler » 14 Aug 2022, 07:29

aliztori wrote: isnt work
I can’t help with this kind of feedback. I’ll leave it to others to continue.

aliztori
Posts: 119
Joined: 19 Jul 2022, 12:44

Re: Error In GUI

Post by aliztori » 14 Aug 2022, 08:02

boiler wrote:
14 Aug 2022, 07:29
aliztori wrote: isnt work
I can’t help with this kind of feedback. I’ll leave it to others to continue.
Bro i'm so Sorry im so tired I have been stuck with this code since morning. If you can help me, I would be grateful

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Error In GUI

Post by BoBo » 14 Aug 2022, 08:19

The error message states an error at line 415 (that is btw part of an #Included script), while the code you're providing hasn‘t that number of lines (and is lacking the #Include script as well). Means, your supporters are forced to join a guessing game. And TBH, I doubt that this is "your" code as otherwise you would be able to handle that issue of a "duplicate" variable as the error message is indicating quite obviously.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Error In GUI

Post by wetware05 » 14 Aug 2022, 09:22

boiler, I think it makes use of a translator, and what meant is that the script doesn't work.

BoBo, when a GUI has a vValue, it is cleared using the GUi, destroy command, but what if it's in a loop? the solution that I have given is to add a changing data at the end of the value, but the comment I made above is not entirely correct, because the changing variable %A_Index% can be used, so that the value remains as vValor%A_Index% .

We are all here to learn (some more than others). Nobody knows everything, we all know different things (or different ways of doing it). Is there any other way to do things? If you know the answer, please show us how to avoid the duplicate variable name error.

I don't speak English either and I use translators, I hope they understand me.

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

Re: Error In GUI

Post by boiler » 14 Aug 2022, 11:18

wetware05 wrote: boiler, I think it makes use of a translator, and what meant is that the script doesn't work.
I understood exactly what he was saying. The point was the lack of any information, which is necessary since a full potentially working script wasn't provided, as BoBo mentioned. He didn't say whether there was an AHK error, what it was, or if it ran but it didn't do what was expected, what it actually did do, etc. The person asking for help has to put in some effort in describing the situation if they expect help.

wetware05 wrote: when a GUI has a vValue, it is cleared using the GUi, destroy command, but what if it's in a loop? the solution that I have given is to add a changing data at the end of the value, but the comment I made above is not entirely correct, because the changing variable %A_Index% can be used, so that the value remains as vValor%A_Index% .
I had already mentioned what to do when it's in a loop: You don't put the part where it creates the GUI in a loop. There's no reason for that. You just put the part that shows the GUI in a loop -- not the part that creates it. Adding %A_Index% to the end of the variable name is a really bad approach because then you're just allowing it to avoid the error by creating multiple GUIs indefinitely (big memory leak, among other issues) instead of just coding it correctly to use the same GUI.

Also, as I mentioned previously, the variable name is not vValue. It's Value. The first v is the indicator of the option to attach a variable whose name follows the v. So when you add a control with the vValue option, the variable name is Value, not vValue. You'll never get it to work until you get that straight.

Both of the above things were mentioned before. It also makes it difficult to help when having to repeat the same things.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Error In GUI

Post by wetware05 » 14 Aug 2022, 12:13

Thank you boiler for your information and patience. I already know that the first v in vValue is just a way to identify a variable in a GUI, and the variable name, in this case, is "Value".

Since I don't know much, for now I stick to "trial and error". Sometimes I try what has worked for me in other cases, but they are not always extrapolated to other cases.

In the example of the script below, created by me, it is necessary to add %A_Index%, otherwise it could not work, since it generates as many buttons as indicated by the "SesionName" variable and they could not contain the same names of the variables. Maybe there is another way to do it, but I'm learning, I apply what I know at the moment. Since it worked for me in that case, I tried in aliztori's script, but without success, because it is a totally different case. I'm going to catch on little by little.

Code: Select all

Loop, %CorpusCount%
{
   NameTemp := "HTMLTemp\Name" A_Index ".txt"
   FileRead, Name1, %NameTemp%
   FileAppend, %Name1%`n, SesionName.txt
}
Loop, read, SesionName.txt
   {
   posy:=20*(A_Index-1)
   Gui, ContextClip: Add, Button, x0 y%posy% w20 h20 hwndIcon hwndIcon8 gGoURL vTURL%A_Index%, %A_Index%
   Gui, ContextClip: Add, Button, x520 y%posy% w20 h20 hwndIcon gTxtLabel vTCopy%A_Index%, %A_Index%
   Gui, ContextClip: Add, Button, x540 y%posy% w20 h20 hwndIcon1 gTxtPlane vTplane%A_Index%
   Gui, ContextClip: Add, Button, x20 y%posy% w20 h20 hwndIcon10 gClipDelete vDeleteButton%A_Index%
   Gui, ContextClip: Add, Button, x500 y%posy% w20 h20 hwndIcon9 gTitleEditing vEditing%A_Index%
   Gui, ContextClip: Add, Button, x40 y%posy% w460 h20 gButtonLabel vNameButton%A_Index%, %A_LoopReadLine%
   GuiButtonIcon(Icon, "Resources\clipboard.ico", 1, "s32")
   GuiButtonIcon(Icon1, "Resources\128.ico", 1, "s32")
   GuiButtonIcon(Icon8, "Resources\ArrowSmall.ico", 1, "s32")
   GuiButtonIcon(Icon10, "Resources\recycle 2.ico", 1, "s32")
   GuiButtonIcon(Icon9, "Resources\pencil 1.ico", 1, "s24")
   }
In the end I opted for someone to give a different answer and skip over the SetTimer and loop issue, and mikeyww seems to have provided a good solution at: viewtopic.php?f=76&t= 107352

Post Reply

Return to “Ask for Help (v1)”