Assistance with Functions Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Assistance with Functions

03 Jan 2018, 09:50

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?
Guest

Re: Assistance with Functions  Topic is solved

03 Jan 2018, 10:16

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
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Assistance with Functions

03 Jan 2018, 11:19

That seems to have done the trick. Thanks alot.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 131 guests