0

looking to go backwards through this loop and cant work out the format.

For Each subele As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")

thanks in advance

1 Answers1

2

You can't. A For Each loop direction can't be controlled. What you can do is replace it with a for loop:

'' Note: Option infer should be set to ON for this line!
Dim elements = WebBrowser1.Document.GetElementsByTagName("div")
For i as Integer = elements.Length To 0 Step -1
    Dim subele As HtmlElement = elements(i)
Next

If you only need the last element returned from GetElementsByTagName you can simply do this:

Dim elements = WebBrowser1.Document.GetElementsByTagName("div")
Dim subele As HtmlElement = elements(elements.Length-1) ' or perhaps Count, I'm not sure if this method returns an array, a list, or simply an IEnumerable...
Zohar Peled
  • 79,642
  • 10
  • 69
  • 121