Skip to content Skip to sidebar Skip to footer

Compare Index Of 2 Elements In A Collection

Issue : I have some issues figuring out a way to select elements in my HTMLDocument which are under a certain point in the page. In the following code sample, as you can see in th

Solution 1:

Untested but I would do something like this (assuming I understood you correctly)

Sub Tester()

    Const S_MATCH AsString = "td[width='100'][class='ListMainCent'][rowSpan='1'][colSpan='1']"Dim e, tbl, bHit AsBoolean'...'load page etc'...'get all the matching rows and cycle though themForEach e In IEDoc.querySelectorAll(S_MATCH)

        'did we get to the table of interest yet?IfNot bHit ThenSet tbl = e.ParentNode.ParentNode.ParentNode.ParentNode. _
                        ParentNode.ParentNode.ParentNode
            If IsPartUsageTable(tbl) Then bHit = TrueEndIfIf bHit Then'we reached the table of interest, so'  do something with eEndIfNextEndSubFunction IsPartUsageTable(tbl) AsBooleanDim e, rv AsBooleanForEach e In tbl.getElementsByClassName("SectionHead")
        If Element.innerHTML = "Part Usage"Then
            rv = TrueExitForEndIfNext
    IsPartUsageTable = rv
EndFunction

Solution 2:

Ok, so as unexpected as it sounds, I think I found a solution to my own question. I will confirm you that it works as soon as I have the possibility to run it with my colleague. So I keep point 1 and 2 from my initial post and I replaced point 3 with the following :

For i = 0To IEDoc.getElementsByTagName("form")(0).getElementsByTagName("table").length 
          If IEDoc.getElementsByTagName("form")(0).getElementsByTagName("table")(i).ID = "Stop"Then
                index_Part_Usage = i
                Position_Part_Usage = index + 1ExitForEndIfNext'MsgBox Position_Part_UsageFor i = 0To IEDoc.getElementsByTagName("form")(0).getElementsByTagName("table").length
          If IEDoc.getElementsByTagName("form")(0).getElementsByTagName("table")(i).className = "Bim"Then
                index = i
                Position = index + 1If index > index_Part_Usage ThenForEach Element2 In IEDoc.getElementsByTagName("form")(0).getElementsByTagName("table")(i).querySelectorAll("td[width='100'][class='ListMainCent'][rowSpan='1'][colSpan='1']") ' Now we are in the table which contains the part numbers and we'll look for all the part numbers it contains by applying the queryselectorall again, but this time only in this specific table

                        array_parts2(iteration2) = IEDoc.getElementsByTagName("form")(0).getElementsByTagName("table")(i).querySelectorAll("td[width='100'][class='ListMainCent'][rowSpan='1'][colSpan='1']")(iteration2).innerHTML

                         ActiveWorkbook.Worksheets(1).Cells(iteration2 + 1, 19) = array_parts2(iteration2)

                        iteration2 = iteration2 + 1NextEndIfEndIfNext i

Post a Comment for "Compare Index Of 2 Elements In A Collection"