Script was working Friday, not working Monday

Get help with using AutoHotkey and its commands and hotkeys
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Script was working Friday, not working Monday

15 Apr 2019, 10:36

Hi all, hoping you can help figure this out because I am hitting a wall, and my fellow BAs look at me funny when I extol the virtues of ahk. =)

All was working well on Friday, running a simple script to automate keyboard and mouse input to consistently download raw data and upload to SharePoint, as I have done for the past two years. Then today on Monday I run the same script, no modifications from Friday, and receive the "Call to nonexistent function" error. Ok, fine, so I move my #include with functions from the bottom to the top of my script, and the error is now "Target label does not exist" to the Gosub. I feel like it's not reading the entire script in a first pass, then executing the script, as I believe it should.

I'm running the portable version of ahk (for not being able to install my own programs), just updated this morning from 1.1.23 to 1.1.30.03 to try to fix it, to no avail. Any clues to what could be going on will be greatly appreciated!
MannyKSoSo
Posts: 348
Joined: 28 Apr 2018, 21:59

Re: Script was working Friday, not working Monday

15 Apr 2019, 11:03

could you provide the script (and possibly the error message) to see where you script could be going wrong. A little hard to fix without being able to see code.
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Re: Script was working Friday, not working Monday

15 Apr 2019, 12:25

It's not so much the code but trying to figure out what changed in the environment to no longer run Gosub. If the code will help, here it is (I am not proud of this code, but it works for what I need in a reasonable amount of time):

Code: Select all

;
; AutoHotkey Version: 1.1.23
; Language:       English
; Platform:       Windows 10 Enterprise
; Author:         Rich Suchoski <ras002@hotmail.com>

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetKeyDelay, 10
SetMouseDelay, 50

FormatTime, TimeString, T12, HHmm
FormatTime, DateString, , yyyy-MM-dd

; Run(1) or Test(2) loop
ProjectLoopNumber = 1
Loop 5
{
send #r
WinWaitActive ahk_class #32770
sleep 1000
SetKeyDelay, 0
send \\Application Data\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Excel 2016.lnk{enter}
SetKeyDelay, 10
WinWaitActive ahk_class XLMAIN
sleep 1000
send {enter}
WinWaitActive Book1 - Excel
sleep 1000
ExcelBook1UniqueID := WinActive (Book1 - Excel)

; Find HP ALM tab
Gui, Add, Picture, vpicture hwndMyPic, HP ALM Run and Test download\HP ALM tab.PNG
ControlGetPos, x, y, w, h, , ahk_id %MyPic%
Gui, destroy
ImageSearch, xx, yy, 0, 0, A_ScreenWidth, A_ScreenHeight, HP ALM Run and Test download\HP ALM tab.PNG
xclickHPALMtab := xx+w/2
yclickHPALMtab := yy+h/2

; Click HP ALM tab
click %xclickHPALMtab%, %yclickHPALMtab%
sleep 500
; Click Switch Project
Click, 16, 107
WinWaitActive Connect To ALM

send {tab}
send +{home}
send https nalm.it.census.gov /qcbin{tab}  Broken Link for safety
send %CENusr%{tab}
send {raw}%CENpwd%
send {enter}
PixelGetColor, pixelColorCurrent, 452, 404
while pixelColorCurrent != 0xFFFFFF
{
PixelGetColor, pixelColorCurrent, 452, 404
sleep 500
}

; sleep 5000

; Project dropdown
Click, 488, 434
; Project click start
; Enumeration
if ProjectLoopNumber = 1
{
Click, 450, 450
}
; Interface 
else if ProjectLoopNumber = 2
{
Click, 450, 462
}
; ISR
else if ProjectLoopNumber = 3
{
Click, 450, 475
}
; L_and_M
else if ProjectLoopNumber = 4
{
Click, 450, 487
}
; OCS
else if ProjectLoopNumber = 5
{
Click, 450, 504
}

; Click Login
Click, 265, 525
WinWaitActive Book1 - Excel
sleep 1000

; Initialize project loop counter
RunOrTestLoop = 1
Loop 2
{

; Click New Report
;
; Click HP ALM tab
sleep 2000
click %xclickHPALMtab%, %yclickHPALMtab%
; Click New Report
Click, 506, 106
; develop to get around crashing
sleep 5000
if WinExist("ahk_class #32770")
{
WinActivate ahk_class #32770
sleep 1000
send {space}
sleep 1000
if WinExist("ahk_exe dwwin.exe")
 WinActivate ahk_exe dwwin.exe
 sleep 1000
 send {space}
sleep 5000
send #r
WinWaitActive ahk_class #32770
sleep 1000
SetKeyDelay, 0
send \\Application Data\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Excel 2016.lnk{enter}
SetKeyDelay, 10
WinWaitActive ahk_class XLMAIN
sleep 1000
send {enter}
WinWaitActive Book1 - Excel
sleep 1000
if (RunOrTestLoop = 2)
 {
 send ^n
 sleep 1000
 send {enter}
 WinWaitActive Book2 - Excel
 sleep 2000
 send !{f4}
 sleep 2000
 }
; Click HP ALM tab
click %xclickHPALMtab%, %yclickHPALMtab%
sleep 500
; Click Switch Project
Click, 16, 107
WinWaitActive Connect To ALM

send {tab}
send +{home}
send https nalm.it.census.gov /qcbin{tab}  Broken Link for safety
KeyWait, enter
PixelGetColor, pixelColorCurrent, 452, 404
while pixelColorCurrent != 0xFFFFFF
{
PixelGetColor, pixelColorCurrent, 452, 404
sleep 500
}

; sleep 5000

; Project dropdown
Click, 488, 434
; Project click start
; Enumeration
if ProjectLoopNumber = 1
{
Click, 450, 450
}
; Interface 
else if ProjectLoopNumber = 2
{
Click, 450, 462
}
; ISR
else if ProjectLoopNumber = 3
{
Click, 450, 475
}
; L_and_M
else if ProjectLoopNumber = 4
{
Click, 450, 487
}
; OCS
else if ProjectLoopNumber = 5
{
Click, 450, 504
}

; Click Login
Click, 265, 525
WinWaitActive Book1 - Excel
sleep 1000

; Click HP ALM tab
click %xclickHPALMtab%, %yclickHPALMtab%
; Click New Report
Click, 506, 106
}

WinWaitActive Add Worksheet
Sleep, 500
; Go to list, select Runs or Tests
send {tab 6}
if RunOrTestLoop = 1
{
send {down 21}
}
else if RunOrTestLoop = 2
{
send {down 30}
}
send {tab}{enter}
; WinWaitActive Generate
if RunOrTestLoop = 1
{
WinWaitActive Book2 - Excel
}
else if RunOrTestLoop = 2
{
WinWaitActive Book3 - Excel
}
sleep 1000
PixelGetColor, pixelColorCurrent, 518, 231
while pixelColorCurrent != 0xFFFFFF
{
PixelGetColor, pixelColorCurrent, 518, 231
sleep 500
}
sleep 500

; Click HP ALM tab, Increase Row Limit
; Click HP ALM tab
click %xclickHPALMtab%, %yclickHPALMtab%
; Click Increase Row Limit
Click, 364, 103
Send, 100000

; Refresh
; Click HP ALM tab
click %xclickHPALMtab%, %yclickHPALMtab%
; Refresh
Click, 409, 101
WinWaitActive Generating
if RunOrTestLoop = 1
{
WinWaitActive Book2 - Excel
}
else if RunOrTestLoop = 2
{
WinWaitActive Book3 - Excel
}
sleep 2000

;  Select whole sheet
send ^a
send ^a
send ^a
Sleep, 1000
; Click Wrap Text twice
send !hw
sleep 1000
send !hw
sleep 1000

; Sheet Mod: Copy last refreshed to Sheet1, move column names to row 1
; Select rows
send ^{up}
send ^{up}
sleep 500
send +^{right}
send +{down}
Sleep, 500
; Cut rows
Send, ^x
Sleep, 1000
; Open Sheet1 tab
send ^{PgUp}
Sleep, 1000
; Paste row
Send, ^v
Sleep, 1000
; Back to other sheet
send ^{PgDn}
Sleep, 1000
; Delete rows
send {AppsKey}d
Sleep, 500
; End Sheet Mod

; Cursor in A1
send ^{up}
Sleep, 1000

; Save dated file
;
Gosub FileSave
send {space}
Send %DateString%-%TimeString%
Send, {Enter}
WinWaitActive HP ALM eCaSE
sleep 10000

; Save general file
;
Gosub FileSave
send {Enter}
sleep 5000
send {tab 2}{enter}
; For second run of the day
sleep 10000
send {enter}
; End For second run of the day
WinWaitActive HP ALM eCaSE
sleep 10000

; Close and reset for next run
send !{f4}
if WinActive("ahk_class XLMAIN") != ExcelBook1UniqueID
send !{f4}
WinWaitActive Book1 - Excel
sleep 1000

RunOrTestLoop := ++RunOrTestLoop
}

send !{f4}
sleep 5000
while WinExist("ahk_class #32770")
{
WinActivate ahk_class #32770
sleep 1000
send !{f4}
if WinActive("ahk_exe dwwin.exe")
 click 342, 13
sleep 2000
}
Sleep, 1000

ProjectLoopNumber := ++ProjectLoopNumber
}

msgbox, Done!`n`nPress Esc to exit script


;=====Functions=====
#include ~common functions.ahk


;=====Subs=====
FileSave:
{
; Click HP ALM tab
click %xclickHPALMtab%, %yclickHPALMtab%
; Click Save As
Click, 588, 112
WinWaitActive ahk_class Net UI Tool Window
; Click Save to file
Click, 33, 14
WinWaitActive Save As
sleep 1000
send {tab 10}{enter}H:\Documents\ECaSE\RTVM\HP ALM{enter}
Sleep, 1000
send {tab 6}
Sleep, 1000

Send, HP{space}ALM{space}eCaSE

if ProjectLoopNumber = 1
{
Send, _Enumeration_
}
else if ProjectLoopNumber = 2
{
Send, _Interface_
}
else if ProjectLoopNumber = 3
{
Send, _ISR_
}
else if ProjectLoopNumber = 4
{
Send, _L_and_M_
}
else if ProjectLoopNumber = 5
{
Send, _OCS_
}

Send, agile_

if RunOrTestLoop = 1
{
send Runs
}
else if RunOrTestLoop = 2
{
send Tests
}

return
}

Esc::ExitApp ; Esc key quits script
f12::
suspend, toggle
return
MannyKSoSo
Posts: 348
Joined: 28 Apr 2018, 21:59

Re: Script was working Friday, not working Monday

15 Apr 2019, 12:34

#include ~common functions.ahk
does your filename actually have the ~ in there?
SOTE
Posts: 546
Joined: 15 Jun 2015, 06:21

Re: Script was working Friday, not working Monday

15 Apr 2019, 18:15

If you are making lots of changes to scripts and then running the different versions of it, you should probably put #SingleInstance force
(https://autohotkey.com/docs/commands/_SingleInstance.htm) at the top of the script.

What can happen is that you are actually running an older version of your script, and not the latest one with the new changes. So that errors that you made will not be noticed until much later. The user will be thinking they didn't change anything at that time, so don't know why the script suddenly "broke".

It's also a good idea to put comments into your code and track your changes, to include version number tracking of different versions of your scripts, so that if you do get errors, it's easier to track what changes might have caused them. If you just haphazardly make changes to the code of your script, it becomes much harder to figure out how and why something went wrong.

"Target label does not exist", is usually referring to incorrect spelling of a label's name, the label is coded wrong (like label and not the colon at the end, label:), or that the label is not there.

A label and a function are different from each other. FileSave: looks confused. If you want it to be a label, then you don't need the curly bracket directly underneath it "{". Decide which that you want to use, a function (https://autohotkey.com/docs/Functions.htm) or a label (https://autohotkey.com/docs/misc/Labels.htm). Labels are often easier to use, and are used with Gosub and Goto.

Return is usually the last part of label, not a curly bracket "}" floating in empty space and after the Return. When used with Gosub, you return to the same part of the script that you "jumped from". (https://autohotkey.com/docs/commands/Return.htm). So, looks like more confusion about using a function or a label.

The control flow logic looks awkward. From your comments, it's like you may want to divide your code into different sections, that do different tasks. Thus labels are usually made to divide tasks by subroutine, but here you have almost all the code as one continuous block that runs straight down, except for the Gosub to FileSave.

Proper indentation, like comments, also helps to understand control flow logic and catch errors. By having everything "flat", especially for scripts with more code in them, if becomes harder to see what's going on.

Code: Select all

FileSave:
{   ; why is this here?

...

return
}  ; What is this here for?
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Re: Script was working Friday, not working Monday

16 Apr 2019, 11:18

Thanks for looking into this!

MannyKSoSo - Yes, the file has the "~" in the name.

SOTE - I had #SingleInstance at one point, but didn't need it since I run it only once a day. Though I don't believe the code is the issue since no modifications were made between Friday and Monday.

No need to look at the code, I'm not asking for a script review, especially on such a thrown-together script (from a few different contributors with varying levels of competence, and no indentation like you mentioned, SOTE. Makes me feel dirty every time I look at it).
I'm asking what corporate environment changes could have happened which would cause a script that was working on Friday to not work on Monday. So far the clues are:
  • #include or functions at the end of the file causes the functions to not be recognized
  • Gosub gives the error "Target label does not exist"
  • SetTimer runs only once (just discovered this piece of joy)
It's acting like it's not reading the entire file on the first pass to enable functions and labels, and now SetTimer is throwing me for a loop (all puns intended). An infinite Loop still works:

Does not work:

Code: Select all

SetTimer, MoveMouse, 60000

MoveMouse:
	MouseMove,1,0,1,R
	MouseMove,-1,0,1,R
Works:

Code: Select all

loop {
	MouseMove,1,0,1,R
	MouseMove,-1,0,1,R
	sleep 60000
}	
SOTE
Posts: 546
Joined: 15 Jun 2015, 06:21

Re: Script was working Friday, not working Monday

16 Apr 2019, 11:40

ras002 wrote:
16 Apr 2019, 11:18

No need to look at the code, I'm not asking for a script review, especially on such a thrown-together script (from a few different contributors with varying levels of competence, and no indentation like you mentioned, SOTE. Makes me feel dirty every time I look at it).
I'm asking what corporate environment changes could have happened which would cause a script that was working on Friday to not work on Monday.

It's acting like it's not reading the entire file on the first pass to enable functions and labels, and now SetTimer is throwing me for a loop (all puns intended). An infinite Loop still works:
Does not work:

Code: Select all

SetTimer, MoveMouse, 60000

MoveMouse:
	MouseMove,1,0,1,R
	MouseMove,-1,0,1,R
Hmmmm... Well this works. I won't bore you with a script review, but maybe a bit more studying might help. That, or you might want to reinstall AutoHotkey or check if some hacker is screwing around with you.

Works:

Code: Select all

#Persistent

SetTimer, MoveMouse, 5000

MoveMouse:
	MouseMove, 200, 30,10,R
	MouseMove,-200,-30,10,R
Return
MannyKSoSo
Posts: 348
Joined: 28 Apr 2018, 21:59

Re: Script was working Friday, not working Monday

16 Apr 2019, 11:47

On line 338 you are missing the opening { for your if statement (which is throwing stuff off). I would fix that and see if the error continues.
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Re: Script was working Friday, not working Monday

16 Apr 2019, 12:17

MannyKSoSo - Adding the curly brackets around the if statement didn't change anything, still stuck on the Gosub error and won't run.

SOTE - Thanks for the workaround! I can try #Persistent later tonight.

Btw, this script as it is works on my home system, but not on my company system. To get this to work on my company system I have to put the #include at the top of the file, and replace Gosub in the script with the contents of the Gosub (eliminating the use of Gosub).
MannyKSoSo
Posts: 348
Joined: 28 Apr 2018, 21:59

Re: Script was working Friday, not working Monday

16 Apr 2019, 12:36

weird changing the location of #include changes that it works since #includes is run at the very start of the script. As for the gosub could you turn it into a function and make it work?
FanaticGuru
Posts: 1349
Joined: 30 Sep 2013, 22:25

Re: Script was working Friday, not working Monday

16 Apr 2019, 12:42

MannyKSoSo wrote:
16 Apr 2019, 11:47
On line 338 you are missing the opening { for your if statement (which is throwing stuff off). I would fix that and see if the error continues.
I don't think that is the problem. I admit without indenting it can be hard to follow the blocks.

Here is an indented version:

Code: Select all

;
; AutoHotkey Version: 1.1.23
; Language:       English
; Platform:       Windows 10 Enterprise
; Author:         Rich Suchoski <ras002@hotmail.com>

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetKeyDelay, 10
SetMouseDelay, 50

FormatTime, TimeString, T12, HHmm
FormatTime, DateString, , yyyy-MM-dd

; Run(1) or Test(2) loop
ProjectLoopNumber = 1
Loop 5
{
	send #r
	WinWaitActive ahk_class #32770
	sleep 1000
	SetKeyDelay, 0
	send \\Application Data\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Excel 2016.lnk{enter}
	SetKeyDelay, 10
	WinWaitActive ahk_class XLMAIN
	sleep 1000
	send {enter}
	WinWaitActive Book1 - Excel
	sleep 1000
	ExcelBook1UniqueID := WinActive (Book1 - Excel)

	; Find HP ALM tab
	Gui, Add, Picture, vpicture hwndMyPic, HP ALM Run and Test download\HP ALM tab.PNG
	ControlGetPos, x, y, w, h, , ahk_id %MyPic%
	Gui, destroy
	ImageSearch, xx, yy, 0, 0, A_ScreenWidth, A_ScreenHeight, HP ALM Run and Test download\HP ALM tab.PNG
	xclickHPALMtab := xx+w/2
	yclickHPALMtab := yy+h/2

	; Click HP ALM tab
	click %xclickHPALMtab%, %yclickHPALMtab%
	sleep 500
	; Click Switch Project
	Click, 16, 107
	WinWaitActive Connect To ALM

	send {tab}
	send +{home}
	send https nalm.it.census.gov /qcbin{tab}  Broken Link for safety
	send %CENusr%{tab}
	send {raw}%CENpwd%
	send {enter}
	PixelGetColor, pixelColorCurrent, 452, 404
	while pixelColorCurrent != 0xFFFFFF
	{
		PixelGetColor, pixelColorCurrent, 452, 404
		sleep 500
	}

	; sleep 5000

	; Project dropdown
	Click, 488, 434
	; Project click start
	; Enumeration
	if ProjectLoopNumber = 1
	{
		Click, 450, 450
	}
	; Interface 
	else if ProjectLoopNumber = 2
	{
		Click, 450, 462
	}
	; ISR
	else if ProjectLoopNumber = 3
	{
		Click, 450, 475
	}
	; L_and_M
	else if ProjectLoopNumber = 4
	{
		Click, 450, 487
	}
	; OCS
	else if ProjectLoopNumber = 5
	{
		Click, 450, 504
	}

	; Click Login
	Click, 265, 525
	WinWaitActive Book1 - Excel
	sleep 1000

	; Initialize project loop counter
	RunOrTestLoop = 1
	Loop 2
	{

		; Click New Report
		;
		; Click HP ALM tab
		sleep 2000
		click %xclickHPALMtab%, %yclickHPALMtab%
		; Click New Report
		Click, 506, 106
		; develop to get around crashing
		sleep 5000
		if WinExist("ahk_class #32770")
		{
			WinActivate ahk_class #32770
			sleep 1000
			send {space}
			sleep 1000
			if WinExist("ahk_exe dwwin.exe")
				WinActivate ahk_exe dwwin.exe
			sleep 1000
			send {space}
			sleep 5000
			send #r
			WinWaitActive ahk_class #32770
			sleep 1000
			SetKeyDelay, 0
			send \\Application Data\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Excel 2016.lnk{enter}
			SetKeyDelay, 10
			WinWaitActive ahk_class XLMAIN
			sleep 1000
			send {enter}
			WinWaitActive Book1 - Excel
			sleep 1000
			if (RunOrTestLoop = 2)
			{
				send ^n
				sleep 1000
				send {enter}
				WinWaitActive Book2 - Excel
				sleep 2000
				send !{f4}
				sleep 2000
			 }
			; Click HP ALM tab
			click %xclickHPALMtab%, %yclickHPALMtab%
			sleep 500
			; Click Switch Project
			Click, 16, 107
			WinWaitActive Connect To ALM

			send {tab}
			send +{home}
			send https nalm.it.census.gov /qcbin{tab}  Broken Link for safety
			KeyWait, enter
			PixelGetColor, pixelColorCurrent, 452, 404
			while pixelColorCurrent != 0xFFFFFF
			{
				PixelGetColor, pixelColorCurrent, 452, 404
				sleep 500
			}

			; sleep 5000

			; Project dropdown
			Click, 488, 434
			; Project click start
			; Enumeration
			if ProjectLoopNumber = 1
			{
				Click, 450, 450
			}
			; Interface 
			else if ProjectLoopNumber = 2
			{
				Click, 450, 462
			}
			; ISR
			else if ProjectLoopNumber = 3
			{
				Click, 450, 475
			}
			; L_and_M
			else if ProjectLoopNumber = 4
			{
				Click, 450, 487
			}
			; OCS
			else if ProjectLoopNumber = 5
			{
				Click, 450, 504
			}

			; Click Login
			Click, 265, 525
			WinWaitActive Book1 - Excel
			sleep 1000

			; Click HP ALM tab
			click %xclickHPALMtab%, %yclickHPALMtab%
			; Click New Report
			Click, 506, 106
		}

		WinWaitActive Add Worksheet
		Sleep, 500
		; Go to list, select Runs or Tests
		send {tab 6}
		if RunOrTestLoop = 1
		{
			send {down 21}
		}
		else if RunOrTestLoop = 2
		{
			send {down 30}
		}
		send {tab}{enter}
		; WinWaitActive Generate
		if RunOrTestLoop = 1
		{
			WinWaitActive Book2 - Excel
		}
		else if RunOrTestLoop = 2
		{
			WinWaitActive Book3 - Excel
		}
		sleep 1000
		PixelGetColor, pixelColorCurrent, 518, 231
		while pixelColorCurrent != 0xFFFFFF
		{
			PixelGetColor, pixelColorCurrent, 518, 231
			sleep 500
		}
		sleep 500

		; Click HP ALM tab, Increase Row Limit
		; Click HP ALM tab
		click %xclickHPALMtab%, %yclickHPALMtab%
		; Click Increase Row Limit
		Click, 364, 103
		Send, 100000

		; Refresh
		; Click HP ALM tab
		click %xclickHPALMtab%, %yclickHPALMtab%
		; Refresh
		Click, 409, 101
		WinWaitActive Generating
		if RunOrTestLoop = 1
		{
			WinWaitActive Book2 - Excel
		}
		else if RunOrTestLoop = 2
		{
			WinWaitActive Book3 - Excel
		}
		sleep 2000

		;  Select whole sheet
		send ^a
		send ^a
		send ^a
		Sleep, 1000
		; Click Wrap Text twice
		send !hw
		sleep 1000
		send !hw
		sleep 1000

		; Sheet Mod: Copy last refreshed to Sheet1, move column names to row 1
		; Select rows
		send ^{up}
		send ^{up}
		sleep 500
		send +^{right}
		send +{down}
		Sleep, 500
		; Cut rows
		Send, ^x
		Sleep, 1000
		; Open Sheet1 tab
		send ^{PgUp}
		Sleep, 1000
		; Paste row
		Send, ^v
		Sleep, 1000
		; Back to other sheet
		send ^{PgDn}
		Sleep, 1000
		; Delete rows
		send {AppsKey}d
		Sleep, 500
		; End Sheet Mod

		; Cursor in A1
		send ^{up}
		Sleep, 1000

		; Save dated file
		;
		Gosub FileSave
		send {space}
		Send %DateString%-%TimeString%
		Send, {Enter}
		WinWaitActive HP ALM eCaSE
		sleep 10000

		; Save general file
		;
		Gosub FileSave
		send {Enter}
		sleep 5000
		send {tab 2}{enter}
		; For second run of the day
		sleep 10000
		send {enter}
		; End For second run of the day
		WinWaitActive HP ALM eCaSE
		sleep 10000

		; Close and reset for next run
		send !{f4}
		if WinActive("ahk_class XLMAIN") != ExcelBook1UniqueID
			send !{f4}
		WinWaitActive Book1 - Excel
		sleep 1000

		RunOrTestLoop := ++RunOrTestLoop
	}

	send !{f4}
	sleep 5000
	while WinExist("ahk_class #32770")
	{
		WinActivate ahk_class #32770
		sleep 1000
		send !{f4}
		if WinActive("ahk_exe dwwin.exe")
			click 342, 13
		sleep 2000
	}
	Sleep, 1000

	ProjectLoopNumber := ++ProjectLoopNumber
}

msgbox, Done!`n`nPress Esc to exit script


;=====Functions=====
#include ~common functions.ahk


;=====Subs=====
FileSave:
	; Click HP ALM tab
	click %xclickHPALMtab%, %yclickHPALMtab%
	; Click Save As
	Click, 588, 112
	WinWaitActive ahk_class Net UI Tool Window
	; Click Save to file
	Click, 33, 14
	WinWaitActive Save As
	sleep 1000
	send {tab 10}{enter}H:\Documents\ECaSE\RTVM\HP ALM{enter}
	Sleep, 1000
	send {tab 6}
	Sleep, 1000

	Send, HP{space}ALM{space}eCaSE

	if ProjectLoopNumber = 1
	{
		Send, _Enumeration_
	}
	else if ProjectLoopNumber = 2
	{
		Send, _Interface_
	}
	else if ProjectLoopNumber = 3
	{
		Send, _ISR_
	}
	else if ProjectLoopNumber = 4
	{
		Send, _L_and_M_
	}
	else if ProjectLoopNumber = 5
	{
		Send, _OCS_
	}

	Send, agile_

	if RunOrTestLoop = 1
	{
		send Runs
	}
	else if RunOrTestLoop = 2
	{
		send Tests
	}
return

Esc::ExitApp ; Esc key quits script
f12::
	suspend, toggle
return
There was some funkyiness with the FileSave subroutine having braces but that was probably not the problem.

If absolutely nothing changed about your code from Friday to Monday, then it seems like a change in directories or permissions. I would make sure my #Include is happening correctly. Directories normally don't change but security permissions often change in the background with Windows updates.

I would post your #Include file so that people can see if anything funky is going on in that file. There could be commands in your #Include file that are sensitive to permissions. It should also only include functions and not any 'auto-execute' type code. #Include just puts the file in the spot choosen before the script is processed. Not just any code can go anywhere in a script.

The error messages should also state a line that is causing the problem which is often very useful to debugging.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
Lamron750
Posts: 2
Joined: 02 Feb 2019, 19:31

Re: Script was working Friday, not working Monday

16 Apr 2019, 19:10

I've had the same thing happen. A perfectly good script just suddenly stops working for no reason, and refuses to read the #Include file.

Try using the full complete path for the #Include. That's the only thing that works for me. My AHK can't find include files that are in the same folder as the main script. Used to work just fine until it didn't anymore.
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Re: Script was working Friday, not working Monday

16 Apr 2019, 21:24

FanaticGuru - Wow, thanks for the indentation! That's something I've always wanted to do, and never got around to it with all the other fires going on around. =D
Yes!! I believe it's a change of permissions, which is why I'm not worried about proofing the script. Do you think it was a Windows update, or a company policy update? I'm looking to see if this was just a routine change, or if this is leading to no longer supporting the use of ahk (in which case I'm going to have to find another way to do this, quickly since I run this report every day). Here's the #include (terribly sorry about the copy/pasting of my script, I didn't realize it flattened the few indents that are there):

Code: Select all

ClickMiddle(directory,imageToFind,x1,y1,x2,y2) {
	local vpicture
	Gui, Add, Picture, vpicture hwndMyPic, %directory%\%imageToFind%
	ControlGetPos, x, y, w, h, , ahk_id %MyPic%
	Gui, destroy
	xx := ""
	while xx = "" {
		ImageSearch, xx, yy, %x1%, %y1%, %x2%, %y2%, %directory%\%imageToFind%
		sleep 1000
	}
	xclick := xx+w/2
	yclick := yy+h/2
	click %xclick%, %yclick%
	return
}

PicFind(directory,imageToFind,x1,y1,x2,y2,byref w,byref h,byref xx,byref yy) {
	local vpicture
	Gui, Add, Picture, vpicture hwndMyPic, %directory%\%imageToFind%
	ControlGetPos, x, y, w, h, , ahk_id %MyPic%
	Gui, destroy
	xx := ""
	ImageSearch, xx, yy, %x1%, %y1%, %x2%, %y2%, %directory%\%imageToFind%
	return
}
Lamron750 - I'm sorry to hear you've had the same problem, though I'm glad I'm not the only one. The full path wasn't needed, just moving the #include from the bottom to the top of the script cleared that error of not recognizing those functions defined in the #include.

MannyKSoSo - Great idea! Yes, changing that Gosub to a function, which I can put in the #include, and have at the top of the script would be a great workaround to not change my coding style too much. =)

SOTE - Thanks so much! #Persistent works for SetTimer, that gets another of my scripts up and running. =D
SOTE
Posts: 546
Joined: 15 Jun 2015, 06:21

Re: Script was working Friday, not working Monday

16 Apr 2019, 21:39

Maybe add this at the top of your script, after all the # stuff.

Pseudo Code

Code: Select all

#NoEnv 
#Include
#Persistent

If not A_IsAdmin 
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}
Might help, depending on what your permissions are on the computer.
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Re: Script was working Friday, not working Monday

17 Apr 2019, 12:52

SOTE wrote:
16 Apr 2019, 21:39
Maybe add this at the top of your script, after all the # stuff.

Pseudo Code

Code: Select all

#NoEnv 
#Include
#Persistent

If not A_IsAdmin 
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}
Might help, depending on what your permissions are on the computer.
No change, still receive the unknown function error like it's not picking up the #include at the end of the script, or when the #include is at the beginning of the script there's the Gosub error with label not found.
SOTE
Posts: 546
Joined: 15 Jun 2015, 06:21

Re: Script was working Friday, not working Monday

17 Apr 2019, 17:23

ras002 wrote:
17 Apr 2019, 12:52
SOTE wrote:
16 Apr 2019, 21:39
Maybe add this at the top of your script, after all the # stuff.

Pseudo Code

Code: Select all

#NoEnv 
#Include
#Persistent

If not A_IsAdmin 
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}
Might help, depending on what your permissions are on the computer.
No change, still receive the unknown function error like it's not picking up the #include at the end of the script, or when the #include is at the beginning of the script there's the Gosub error with label not found.
I suggest also that you put #Include at the top of your script, which is what is usually done, not at the bottom.

I don't know about using "~", (~common functions.ahk). Why don't you test out typing the full directory path, put "common functions.ahk" in the same directory, rename the Include file you are using, or use things like A_ScriptDir, SetWorkingDir, etc...

Lastly, making a much smaller script, where you test something out is often done. If you are not sure something is working, you can create a small test script which shows definitively that it is or not working. Gosub, in AutoHotkey, definitely works. It's more of you making a test script using Gosub and your FileSave: label that needs to be shown if it works or not. You have so much going on in the script, so in the test script, remove most of that. Then see how the simple test version works.
ras002
Posts: 7
Joined: 15 Apr 2019, 10:00

Re: Script was working Friday, not working Monday

Yesterday, 07:09

@SOTE - Would love your insight with another part of the same problem, the kill switch isn't working. I have this at the end of my files:

Code: Select all

Esc::ExitApp
but since the beginning of this week this hasn't worked as well. Putting this at the top of the script is not an option since it won't progress past it until pressing Esc, which kills it. Any suggestions for making this work, or for a new kill switch?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Odlanir, swagfag, vsub and 26 guests