Is this even possible?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rishu0182
Posts: 33
Joined: 02 Feb 2017, 11:49

Is this even possible?

17 Aug 2018, 11:40

Hello!

So my hope is that I can loop through two separate lists at the same time and verify matching data. Right now this set-up (Thanks Joe Glines!)
This code will loop through the numbers in Var one by one and display the variable vStatus in the msgbox.

Code: Select all

#Persistent

var=
(
1
2
3
4
5
)
var2=
(
a
b
c
d
e
)

F1::
Loop, parse, Var, `n, `r ;loop over Var line by line
{
IfEqual, A_LoopField,,continue ;Skip loop if blank
;IfEqual, A_index,5,break ;Break if index =value
;~ MsgBox,,Loop index and values, % A_index a_tab A_LoopField

pwb := WBGet()  ;included in loop just in case gets dissconnected
URL:="https://www.genericwebsite.com/generic.x?appId=" . A_LoopField ; concatenate url and current row

;***********Navigate to value*******************
pwb.Navigate(URL) ;Navigate to URL
while pwb.busy or pwb.ReadyState != 4 ;Wait for page to load
 Sleep, 100

;***********Grab a data point*******************
Status:=pwb.document.GetElementsByTagName("Span")[3].InnerText ;Get Tagname and Array value
MsgBox STATUS: %Status%
}
return


;************Pointer to Open IE Window******************
WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%

   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
return
What i would like to do is have this code loop through Var AND Var2 at the same time so that I could do something like

Code: Select all

IfInString, A_LoopField, %Status%
{
MSgbox Match!
}
Elses
Msgbox No Match!
Is it possible to run these two loops at the same time to make this match? or should I find a different avenue? I am hoping to avoid Excel as the solution if possible.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Is this even possible?

17 Aug 2018, 12:14

i have a hard time understanding what ure trying to do exactly.
suppose uve managed to do what u wanted to do, what are the contents of A_LoopField for a particular iteration of the loop?
Rishu0182
Posts: 33
Joined: 02 Feb 2017, 11:49

Re: Is this even possible?

17 Aug 2018, 13:24

Hi!
So basically I have a work system that always uses the same url minus the appid.
I have a report that shows me exactly what the status should be on each of those ID's. However to validate that data I would like to load one variable with the app ID, a second variable with what the status SHOULD be, and then as the loop runs through the cases and checks the contents of pwb.document.GetElementsByTagName("Span")[3].InnerText to tell me what the actual real world status is.

I want the program to notify me if the current iteration of Var2 and the text is pulled from SPAN 3 match with a msgbox that says match, and if the status in Span 3 does not match the current iteration of Var2, I want a msgbox to tell me No Match.

So for Var the Loopfield always shows me the app ID, but what I want is for it to be able to match "Var2" and "Status" in each loop.

I hope that makes sense
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Is this even possible?

17 Aug 2018, 16:12

1. u make 2 arrays out of your lists. thats what the strsplit does
2. u pair the items from the first array with the items from the second array, resulting in a new associative array. thats what the for loop does
3. u iterate over all key-value pairs in the associative array with another for-loop. the ID is the key and the status its supposed to have is the value.

Code: Select all

#Persistent

ListIDs =
(
1
2
3
4
5
)

ListStatuses =
(
a
b
c
d
e
)

AppIDs := StrSplit(ListIDs, "`n", "`r")
ExpectedStatuses := StrSplit(ListStatuses, "`n", "`r")

Data := {}
for each, appID in AppIDs
{
	Data[appID] := ExpectedStatuses[A_Index]
}

F1::
	for appID, expectedStatus in Data
	{
		if (appID == "")
			continue

		pwb := WBGet()
		URL := "https://www.genericwebsite.com/generic.x?appId=" appID
		pwb.Navigate(URL)
		while pwb.busy or pwb.ReadyState != 4
			Sleep, 100

		Status := pwb.document.GetElementsByTagName("Span")[3].InnerText

		if (Status == expectedStatus)
			MsgBox Match!
		else
			MsgBox No Match!
	}
return

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {
	static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
	, IID := "{0002DF05-0000-0000-C000-000000000046}"
	SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%

	if (ErrorLevel != "FAIL") {
		lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
		if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
			DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
			return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
		}
	}
}
Rishu0182
Posts: 33
Joined: 02 Feb 2017, 11:49

Re: Is this even possible?

20 Aug 2018, 09:12

Hello!
Let me begin by saying that this is fantastic and I truly appreciate your work on this. This is exactly what I needed and you took the time to help me and for that I am truly grateful.

I was hoping you might be able to assist me with two questions I have about this. The first is that in testing I noticed that if there is a duplicate value in ListIDs, that it will skip to the last instance of that variable. I was curious if it were possible to make this loop not skip anything at all? And my second question, if I wanted to add a third variable, call it ListColor, and each iteration also had a color to check for in the COM, how could I add an additional variable?

Again I greatly appreciate your time and assistance. Thank you
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Is this even possible?

20 Aug 2018, 09:43

1. there cant be any duplicates in an associative array, so we change Data to a simple array ([])
2. iterate over the lists, create an associative array for each list entry, populate it with data and push it into the simple array

Code: Select all

#Persistent

ListIDs =
(
1
2
3
4
5
)

ListStatuses =
(
a
b
c
d
e
)

ListColors =
(
red
green
blue
yellow
purple
)

AppIDs := StrSplit(ListIDs, "`n", "`r")
ExpectedStatuses := StrSplit(ListStatuses, "`n", "`r")
Colors := StrSplit(ListColors, "`n", "`r")

Data := []
for i in AppIDs
{
	Data.Push({"appID": AppIDs[i]
		, "expectedStatus": ExpectedStatuses[i]
		, "color": Colors[i]})
}

F1::
	for each, element in Data
	{
		if (element.appID == "")
			continue

		pwb := WBGet()
		URL := "https://www.genericwebsite.com/generic.x?appId=" appID
		pwb.Navigate(URL)
		while pwb.busy or pwb.ReadyState != 4
			Sleep, 100

		Status := pwb.document.GetElementsByTagName("Span")[3].InnerText

		if (Status == element.expectedStatus)
			MsgBox Match!
		else
			MsgBox No Match!

		MsgBox % "the color is: " element.color
	}
return

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {
	static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
	, IID := "{0002DF05-0000-0000-C000-000000000046}"
	SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%

	if (ErrorLevel != "FAIL") {
		lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
		if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
			DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
			return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
		}
	}
}
Rishu0182
Posts: 33
Joined: 02 Feb 2017, 11:49

Re: Is this even possible?

22 Aug 2018, 12:10

Thank you Sir,
This is precisely what I need. Thank you for also providing the reasoning.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 218 guests