Trouble with Nested IFWinExist commands Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TheFireBat
Posts: 6
Joined: 27 Jan 2019, 22:16

Trouble with Nested IFWinExist commands

15 Feb 2019, 20:09

Hi guys!

I've done a lot of research and tried a few different configurations but can't get this to work correctly.
I'm wanting to cycle through error messages (Using their window titles in a Citrix application.)
The problem is that the errors can be encountered in different order depending on the "Feature" being added through said application.
The best solution would be to CYCLE THROUGH the possible errors on a LOOP multiple times.
I wrote a code to do this however no matter what I've tried the code loops 10 times in a row for each section rather than cycling through the list in order 10 times.

I've tried If exist one after another contained in a big loop, 10 and most recently (Below) even tried a rather large Nested option. (Forgive the numbers I'm still learning nesting elegance.)
Can anyone help me find a way to accomplish my goal?

I can't thank you guys enough... I hate asking, really I do. I'm just really stumped this time!

Code: Select all


Loop, 10

{ ;1
	IfWinExist, SOC (#10052) - \\Remote
		{ ;2
		WinActivate  ; Automatically activates the window found above. (If not already active.)
		Send, {SPACE}
		SLEEP, 100
		SEND, ^r
		SLEEP, %PressedRefresh%
		WinWait, Macro Monster - Excel
		IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
		Send, {right}DUPLICATE{right}
		sleep, 100
		Gosub, LOGICMONSTER	;;;Only EXCLUDE while in module mode for individual ttesting.
		exitapp					;;;Only include while in module mode.
		} ;2
			else
			{ ;3
			IfWinExist, Device SOC Validation Error (#9100047) - \\Remote
				{ ;4
				WinActivate  ; Automatically activates the window found above. (If not already active.)
				Send, {SPACE}
				SLEEP, 100
				SEND, ^r
				SLEEP, %PressedRefresh%
				WinWait, Macro Monster - Excel
				IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
				Send, {right}SOC CONFLICT{right}
				sleep, 100
				Gosub, LOGICMONSTER	;;;Only EXCLUDE while in module mode for individual ttesting.
				exitapp					;;;Only include while in module mode.
				} ;4
					else
					{ ;5
					IfWinExist, SITT/Device SOC Validation Messages - \\Remote
						{ ;6
						WinActivate  ; Automatically activates the window found above. (If not already active.)
						Send, i
						sleep, %PostWarnSplash%
						send, {Space}
						sleep, 200
						GOSUB, Add_Soc_Save_Break
						} ;6
							else
							;SLEEP, %PostWarnSplash%  ;LOOOOOOOOOOOOOOOOOONG sleep due to ridiculous test account. Testing different position
							{ ;7
							IfWinExist, Warning - \\Remote
								{ ;8
								WinActivate  ; Automatically uses the window found above.
								;WinMaximize  ; same (I don't need it maximized but good command to know)
								Send, {SPACE}
								SLEEP, %PostWarnSplash%
								GOSUB, Add_Soc_Save_Break
								} ;8
									ELSE
									{ ;9
									IfWinExist, Required Data (#10202) - \\Remote
										{ ;10
										GOSUB, VM2_Cluster
										} ;10
									} ;9
							} ;7
					} ;5
			} ;3
	Sleep, 200
} ;1

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Trouble with Nested IFWinExist commands

16 Feb 2019, 14:41

What about removing the outer loop, and the "else" parts and just puting all "ifs" in a row (maybe with an loop inside each if)?

And a different idea, since I don't know if 10 is just a magic number, what about using "while" instead of "if" as in while WinExist("SOC (#10052) - \\Remote") ?
TheFireBat
Posts: 6
Joined: 27 Jan 2019, 22:16

Re: Trouble with Nested IFWinExist commands

16 Feb 2019, 15:23

Interesting, I'm unsure of the WHILE command. I'll do some research on it. Could you perhaps expand on the WHILE command in conjunction with multiple IFWINEXIST commands? I truly appreciate the assistance. (It doesn't have to be using my window titles... you can use generic examples.)

Thank you!
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Trouble with Nested IFWinExist commands  Topic is solved

16 Feb 2019, 16:15

What I was thinking about was this (click on expand view):

Code: Select all

while WinExist("SOC (#10052) - \\Remote") {
	WinActivate  ; Automatically activates the window found above. (If not already active.)
	Send, {SPACE}
	SLEEP, 100
	SEND, ^r
	SLEEP, %PressedRefresh%
	WinWait, Macro Monster - Excel
	IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
	Send, {right}DUPLICATE{right}
	sleep, 100
	Gosub, LOGICMONSTER	;;;Only EXCLUDE while in module mode for individual ttesting.
	exitapp					;;;Only include while in module mode.
}

while WinExist("Device SOC Validation Error (#9100047) - \\Remote") {
	WinActivate  ; Automatically activates the window found above. (If not already active.)
	Send, {SPACE}
	SLEEP, 100
	SEND, ^r
	SLEEP, %PressedRefresh%
	WinWait, Macro Monster - Excel
	IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
	Send, {right}SOC CONFLICT{right}
	sleep, 100
	Gosub, LOGICMONSTER	;;;Only EXCLUDE while in module mode for individual ttesting.
	exitapp					;;;Only include while in module mode.
}

while WinExist("SITT/Device SOC Validation Messages - \\Remote") {
	WinActivate  ; Automatically activates the window found above. (If not already active.)
	Send, i
	sleep, %PostWarnSplash%
	send, {Space}
	sleep, 200
	GOSUB, Add_Soc_Save_Break
}

while WinExist("Warning - \\Remote") {
	WinActivate  ; Automatically uses the window found above.
	;WinMaximize  ; same (I don't need it maximized but good command to know)
	Send, {SPACE}
	SLEEP, %PostWarnSplash%
	GOSUB, Add_Soc_Save_Break
}

while WinExist("Required Data (#10202) - \\Remote") {
	GOSUB, VM2_Cluster
}
Without the external loop, just like that.


EDIT:

I just copied your code and reformatted a bit.
But I'm now seeing some ExitApp that could make the script stop sooner than expected.
Last edited by safetycar on 16 Feb 2019, 16:33, edited 2 times in total.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Trouble with Nested IFWinExist commands

16 Feb 2019, 16:30

Does

Code: Select all

IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
Actually work?
TheFireBat
Posts: 6
Joined: 27 Jan 2019, 22:16

Re: Trouble with Nested IFWinExist commands

16 Feb 2019, 21:50

Hellbent wrote:
16 Feb 2019, 16:30
Does

Code: Select all

IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel,
Actually work?
Yes! If the application is running but not active it will force a switch to the active window.
There are other ways of doing it I presume but it does work.
TheFireBat
Posts: 6
Joined: 27 Jan 2019, 22:16

Re: Trouble with Nested IFWinExist commands

16 Feb 2019, 21:57

safetycar wrote:
16 Feb 2019, 16:15
What I was thinking about was this (click on expand view):

Code: Select all

while WinExist("SOC (#10052) - \\Remote") {
	WinActivate  ; Automatically activates the window found above. (If not already active.)
	Send, {SPACE}
	SLEEP, 100
	SEND, ^r
	SLEEP, %PressedRefresh%
	WinWait, Macro Monster - Excel
	IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
	Send, {right}DUPLICATE{right}
	sleep, 100
	Gosub, LOGICMONSTER	;;;Only EXCLUDE while in module mode for individual ttesting.
	exitapp					;;;Only include while in module mode.
}

while WinExist("Device SOC Validation Error (#9100047) - \\Remote") {
	WinActivate  ; Automatically activates the window found above. (If not already active.)
	Send, {SPACE}
	SLEEP, 100
	SEND, ^r
	SLEEP, %PressedRefresh%
	WinWait, Macro Monster - Excel
	IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel, 
	Send, {right}SOC CONFLICT{right}
	sleep, 100
	Gosub, LOGICMONSTER	;;;Only EXCLUDE while in module mode for individual ttesting.
	exitapp					;;;Only include while in module mode.
}

while WinExist("SITT/Device SOC Validation Messages - \\Remote") {
	WinActivate  ; Automatically activates the window found above. (If not already active.)
	Send, i
	sleep, %PostWarnSplash%
	send, {Space}
	sleep, 200
	GOSUB, Add_Soc_Save_Break
}

while WinExist("Warning - \\Remote") {
	WinActivate  ; Automatically uses the window found above.
	;WinMaximize  ; same (I don't need it maximized but good command to know)
	Send, {SPACE}
	SLEEP, %PostWarnSplash%
	GOSUB, Add_Soc_Save_Break
}

while WinExist("Required Data (#10202) - \\Remote") {
	GOSUB, VM2_Cluster
}
Without the external loop, just like that.


EDIT:

I just copied your code and reformatted a bit.
But I'm now seeing some ExitApp that could make the script stop sooner than expected.
Thanks for the while command... I'm unsure still of how to utilize it but I'm looking forward to testing it. do I need something to tell a while command to stop? Is there some way to control the duration of the "WHILE"? Basically the idea is... on pressing save in the application there is an error check period which can vary depending on the overall size of the account. Furthermore the errors (though numbered.) occur out of order and sometimes not at all if all the proper criteria are met. This was why "Looping through" the series of errors several times helps account for the varied load as when they are encountered I can take care of them accordingly and continue the loop. If the while achieves the same effect with less cumbersome implementation... then I am TRULY EXCITED! I'll test it out at work monday and report back. Thanks for your assistance!
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Trouble with Nested IFWinExist commands

16 Feb 2019, 22:09

TheFireBat wrote:
16 Feb 2019, 21:50
Hellbent wrote:
16 Feb 2019, 16:30
Does

Code: Select all

IfWinNotActive, Macro Monster - Excel, , WinActivate, Macro Monster - Excel,
Actually work?
Yes! If the application is running but not active it will force a switch to the active window.
There are other ways of doing it I presume but it does work.
You're short of a few commas. For a one-liner it should be:-

Code: Select all

IfWinNotActive, Macro Monster - Excel,,,, WinActivate, Macro Monster - Excel
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Trouble with Nested IFWinExist commands

17 Feb 2019, 06:12

TAC109 wrote:
16 Feb 2019, 22:09
You're short of a few commas. For a one-liner it should be:-

Code: Select all

IfWinNotActive, Macro Monster - Excel,,,, WinActivate, Macro Monster - Excel
No, it's correct.
Note: Due to backward compatibility, IfWin[Not]Active interpret this parameter as a command if it exactly matches the name of a command. To work around this, use the WinActive function instead.
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Trouble with Nested IFWinExist commands

17 Feb 2019, 16:26

Oh, right. I guess both forms are correct.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TheFireBat
Posts: 6
Joined: 27 Jan 2019, 22:16

Re: Trouble with Nested IFWinExist commands

18 Feb 2019, 10:54

Either way my feelings weren't hurt as it worked! XD Good to know the syntax is acceptable though!
I'll be testing the "While" command today to see how it does. I'll report back here when done. Thanks everyone for your help. In the meantime if anyone has other ideas I'm open to multiple solutions. :)
Thanks for all of your help!
TheFireBat
Posts: 6
Joined: 27 Jan 2019, 22:16

Re: Trouble with Nested IFWinExist commands

18 Feb 2019, 12:30

NICE!

Looks like this is doing the trick!

Code: Select all

408: While,WinExist("SOC (#10052) - \\Remote")
422: While,WinExist("Device SOC Validation Error (#9100047) - \\Remote")
436: While,WinExist("SITT/Device SOC Validation Messages - \\Remote")
445: While,WinExist("Warning - \\Remote")
453: While,WinExist("Required Data (#10202) - \\Remote")
456: Sleep,200 (0.20)
457: }
408: While,WinExist("SOC (#10052) - \\Remote")
422: While,WinExist("Device SOC Validation Error (#9100047) - \\Remote")
436: While,WinExist("SITT/Device SOC Validation Messages - \\Remote")
445: While,WinExist("Warning - \\Remote")
453: While,WinExist("Required Data (#10202) - \\Remote")
456: Sleep,200 (0.20)
457: }
408: While,WinExist("SOC (#10052) - \\Remote")
422: While,WinExist("Device SOC Validation Error (#9100047) - \\Remote")
436: While,WinExist("SITT/Device SOC Validation Messages - \\Remote")
445: While,WinExist("Warning - \\Remote")
453: While,WinExist("Required Data (#10202) - \\Remote")
456: Sleep,200 (0.20)
457: }


It's failing to execute the sub commands for the moment, but it it's looping through the list now quite nicely!
Thanks so very much for the help! I'll tweak it a bit to try and get this thing working. :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: cjsmile999 and 343 guests