Page 1 of 1

Assistance with Functions

Posted: 03 Jan 2018, 09:50
by Crashm87
Morning all,

I stumbled accross a thread last night that suggested using functions throught scripts in place of goto, or gosub.

I thought I would give it a try, I am still learning functions, so I thought I would learn as I go and see if I can replace some subs in a script I have.

The script takes basic variables and inputs them into IE. When I use the gosub, this script works flawlessly. When I changed it to a function, it doesn't use COM.

Code: Select all

oneline:    ;this is called by gui button
condition := 1
tech()
;GoSub, buttonContinue   ; debug
return

tech()
{
	msgbox debug ; this shows up, so it is entering function properly
	wb := IEget()
	getFrame()
	myFrame.querySelectorAll("select")[0].value := "Other"
	Sleep, 100
	myFrame.parentWindow.execScript("enterTechId(market)")
	Sleep, 100
	myFrame.querySelectorAll("INPUT")[52].value := "0768"
	Sleep,100
	myFrame.querySelectorAll("select")[1].selectedIndex := 1
	Sleep, 100
	WinActivate, C5584 - HANOVER CHRYSLER DODGE JEEP DealerCONNECT - Internet Explorer
	;Run %A_ScriptDir%\Close Pop-up.ahk
	myFrame.querySelectorAll("A")[11].click()
	Sleep,1500
	
	;GoSub, closepopup    ;comment out for debug, and it enters the gosub when active, so it is reaching bottom of function
return
}
none of the code is pushed to IE. If i switch this back to a label, and gosub to it, it works flawless. What am I missing?

Re: Assistance with Functions  Topic is solved

Posted: 03 Jan 2018, 10:16
by Guest
Add global to your functions so variables and objects set/created outside the function are accessible.

Code: Select all

tech()
{
global ; add this line

msgbox debug ; this shows up, so it is entering function properly
	wb := IEget()
;......

See https://autohotkey.com/docs/Functions.htm#Global
Tutorial https://autohotkey.com/boards/viewtopic.php?f=7&t=41823

Re: Assistance with Functions

Posted: 03 Jan 2018, 11:19
by Crashm87
That seems to have done the trick. Thanks alot.