Variable loosing value. Please Help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Deaths_Shadow
Posts: 3
Joined: 22 Oct 2017, 21:11

Variable loosing value. Please Help

22 Oct 2017, 22:03

I am having a problem with a variable loosing its value inside of a loop. I am new to autohotkey, and, since this is my first real script, please humor me if my code is hard to read or if I do things that are not efficient (though I would appreciate any criticism to help me improve my scripting). Any assistance resolving the issue with the variable or helping me obtain my goal in an easier way would be appreciated.

I am creating a GUI to collect information that will be used by code I plan to write in the future. The goal of this loop is to detect if the user has inputted any duplicate tool numbers into the GUI.

In this loop, the variable Tool_Counter contains a value of 1 for the first iteration of the loop, but, in all following iterations, the variable is set to null. I have arrived at this conclusion by inserting message boxes into the code to return the value of the variable Tool_Counter.

Code: Select all

 
Tool_Number:= 1
loop 
{
	Tool_Number:= %Tool_Number%+1
	Tool_Counter:= 0
	Loop
	{
		While (Tool_Counter < 16)
		{
			Tool_Counter:= %Tool_Counter%+1
			If ( Tool_Number = Tool_Counter)
			{
					continue
			}
			Else
			{
				Place_Holder_Tool:= % Tool_Input_%Tool_Number%
				Place_Holder_Counter:= % Tool_Input_%Tool_Counter%
				If ( %Place_Holder_Tool% = %Place_Holder_Counter% )
				{
					msgbox Duplicate Tool Detected
				}
				Else
				{
					continue
				}
			}
		}
	break
	}
	If (Tool_Number = 15)
	{
		break
	}
	else
	{
		continue
	}
}		
Though I believe that the issue is isolated to the code listed above, here is the whole script. Please note that the loop where my problem is arising is under the g-lable "Submit_Button"

Code: Select all

#SingleInstance, force

gui, show, x1600 y100 w600 h650, 
gui, +alwaysontop
gui, add, text, section, Select Machine:
gui, add, DropDownList, gMachine vMachine Choose%Machine_Definition%, Ganesh|Haas
gui, add, text, w140 vText1,
gui, add, edit, Uppercase vProgram_Name
gui, add, text,, Part Name && Number
gui, add, edit, Uppercase vPart_Name
gui, add, text,, Stock Diameter
gui, add, edit, vStock_Diameter
gui, add, text,, Stock Material
gui, add, combobox, vStock_Material, |6061 Al|7075 Al|12L14|1018|1045|4140|303 SS|306 SS|316 SS|Tool Steel|
gui, add, text,, Part Stick Out
gui, add, edit, vPart_Stick_Out
gui, add, text,, Default Spindle Limit
gui, add, edit, vDefault_Spindle_Limit
gui, add, text,, Turning SFM
gui, add, edit, VSFM
gui, add, text,, Coolant Options
gui, add, DropDownList, vCoolant,
gui, add, text,, Lathe Tool Tips:
gui, add, text, section ys, Tool Number:
gui, add, text, ys w120, Tool Description:
gui, add, text, ys x+85, Tool Radius:
gui, add, text, ys, Tool Tip:
gui, add, edit, section xs w60 Number vTool_Input_1
gui, add, edit, ys w200 Uppercase vTool_Description_1
gui, add, edit, ys w60 vTool_Radius_1
gui, add, edit, ys Number W50 vTool_Tip_1
gui, add, edit, section xs w60 Number vTool_Input_2
gui, add, edit, ys w200 Uppercase vTool_Description_2
gui, add, edit, ys w60 vTool_Radius_2
gui, add, edit, ys Number W50 vTool_Tip_2
gui, add, edit, section xs w60 Number vTool_Input_3
gui, add, edit, ys w200 Uppercase vTool_Description_3
gui, add, edit, ys w60 vTool_Radius_3
gui, add, edit, ys Number W50 vTool_Tip_3
gui, add, edit, section xs w60 Number vTool_Input_4
gui, add, edit, ys w200 Uppercase vTool_Description_4
gui, add, edit, ys w60 vTool_Radius_4
gui, add, edit, ys Number W50 vTool_Tip_4
gui, add, edit, section xs w60 Number vTool_Input_5
gui, add, edit, ys w200 Uppercase vTool_Description_5
gui, add, edit, ys w60 vTool_Radius_5
gui, add, edit, ys Number W50 vTool_Tip_5
gui, add, edit, section xs w60 Number vTool_Input_6
gui, add, edit, ys w200 Uppercase vTool_Description_6
gui, add, edit, ys w60 vTool_Radius_6
gui, add, edit, ys Number W50 vTool_Tip_6
gui, add, edit, section xs w60 Number vTool_Input_7
gui, add, edit, ys w200 Uppercase vTool_Description_7
gui, add, edit, ys w60 vTool_Radius_7
gui, add, edit, ys Number W50 vTool_Tip_7
gui, add, edit, section xs w60 Number vTool_Input_8
gui, add, edit, ys w200 Uppercase vTool_Description_8
gui, add, edit, ys w60 vTool_Radius_8
gui, add, edit, ys Number W50 vTool_Tip_8
gui, add, edit, section xs w60 Number vTool_Input_9
gui, add, edit, ys w200 Uppercase vTool_Description_9
gui, add, edit, ys w60 vTool_Radius_9
gui, add, edit, ys Number W50 vTool_Tip_9
gui, add, edit, section xs w60 Number vTool_Input_10
gui, add, edit, ys w200 Uppercase vTool_Description_10
gui, add, edit, ys w60 vTool_Radius_10
gui, add, edit, ys Number W50 vTool_Tip_10
gui, add, edit, section xs w60 Number vTool_Input_11
gui, add, edit, ys w200 Uppercase vTool_Description_11
gui, add, edit, ys w60 vTool_Radius_11
gui, add, edit, ys Number W50 vTool_Tip_11
gui, add, edit, section xs w60 Number vTool_Input_12
gui, add, edit, ys w200 Uppercase vTool_Description_12
gui, add, edit, ys w60 vTool_Radius_12
gui, add, edit, ys Number W50 vTool_Tip_12
gui, add, edit, section xs w60 Number vTool_Input_13
gui, add, edit, ys w200 Uppercase vTool_Description_13
gui, add, edit, ys w60 vTool_Radius_13
gui, add, edit, ys Number W50 vTool_Tip_13
gui, add, edit, section xs w60 Number vTool_Input_14
gui, add, edit, ys w200 Uppercase vTool_Description_14
gui, add, edit, ys w60 vTool_Radius_14
gui, add, edit, ys Number W50 vTool_Tip_14
gui, add, edit, section xs w60 Number vTool_Input_15
gui, add, edit, ys w200 Uppercase vTool_Description_15
gui, add, edit, ys w60 vTool_Radius_15
gui, add, edit, ys Number W50 vTool_Tip_15
gui, add, Picture, x10 y435 w300 h200, C:\Users\Selva\Desktop\Autohotkey\Scripts\tool_orientation.jpg
gui, add, button, x400 y435default gSubmit_Button, Submit



Machine:
Coolant_Ganesh =  |Air|Coolant|Off
Coolant_Haas =  |Coolant|Off
Gui, Submit, NoHide
If Machine = Ganesh
     {
     GuiControl, , Text1, Program Name
	SubList:=Coolant_Ganesh
	GuiControl,,Coolant, %SubList%
	Machine_Definition:=1
     }
	 If Machine = Haas
     {
     GuiControl, , Text1, Program Number
	SubList:=Coolant_Haas
	GuiControl,,Coolant, %SubList%
	Machine_Definition:=1
     }
	 return

Submit_Button:
{
Tool_Number:= 1
loop 
{
	Tool_Number:= %Tool_Number%+1
	Tool_Counter:= 0
	Loop
	{
		While (Tool_Counter < 16)
		{
			Tool_Counter:= %Tool_Counter%+1
			If ( Tool_Number = Tool_Counter)
			{
					continue
			}
			Else
			{
				Place_Holder_Tool:= % Tool_Input_%Tool_Number%
				Place_Holder_Counter:= % Tool_Input_%Tool_Counter%
				If ( %Place_Holder_Tool% = %Place_Holder_Counter% )
				{
					msgbox Duplicate Tool Detected
				}
				Else
				{
					continue
				}
			}
		}
	break
	}
	If (Tool_Number = 15)
	{
		break
	}
	else
	{
		continue
	}
}			
Gui, Submit, Hide
return
}

^r:: 
	ExitApp
^t::
	Pause
If you see my error, I would greatly appreciate it if you could inform me of what I am doing wrong.

Thank you
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Variable loosing value. Please Help  Topic is solved

22 Oct 2017, 23:21

Change:

Code: Select all

Tool_Number:= %Tool_Number%+1
to:

Code: Select all

Tool_Number:= Tool_Number+1
and the same for:

Code: Select all

Tool_Counter:= %Tool_Counter%+1
to:

Code: Select all

Tool_Counter:= Tool_Counter+1
as well as :

Code: Select all

If ( %Place_Holder_Tool% = %Place_Holder_Counter% )
to:

Code: Select all

If ( Place_Holder_Tool = Place_Holder_Counter )
When using Expression operator := do not use %'s to deref a variable.

HTH
Deaths_Shadow
Posts: 3
Joined: 22 Oct 2017, 21:11

Re: Variable loosing value. Please Help

23 Oct 2017, 00:57

Thank you. Those changes fixed my error. However, I have another question if I shouldn't use %'s to designate variables.
I have two more problems in my code inside the loop posted above

Place_Holder_Tool:= Tool_Input_%Tool_Number%
Place_Holder_Counter:= Tool_Input_%Tool_Counter%

The variables Place_Holder_Tool and Place_Holder_ Counter are always returning null instead of what I'm expecting them to be. If I shouldn't use %'s how should I designate the value of these variables since I am trying to set them to a changing variable?
Deaths_Shadow
Posts: 3
Joined: 22 Oct 2017, 21:11

Re: Variable loosing value. Please Help

23 Oct 2017, 07:54

I solved the issue. I had failed to submit the contents of my GUI before trying to compare variables which is why everything was returning null.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 216 guests