|
-
Sep 30th, 2013, 08:16 AM
#12
Thread Starter
Junior Member
Re: Pulling an Element From an HTML Array Using WebBrowser
 Originally Posted by jayinthe813
Instead of counting you could do:
Code:
For Each OptElement As HtmlElement In WebBrowser1.Document.Body.GetElementsByTagName("option")
If OptElement.GetAttribute("value") <> "" And Not counties.ContainsKey(OptElement.GetAttribute("value")) Then
counties.Add(OptElement.GetAttribute("value"), OptElement.InnerText)
End If
Next OptElement
If it is impossible to reach an empty string in your collection you could also do
Code:
For Each OptElement As HtmlElement In WebBrowser1.Document.Body.GetElementsByTagName("option")
If OptElement.GetAttribute("value") <> "" And Not counties.ContainsKey(OptElement.GetAttribute("value")) Then
counties.Add(OptElement.GetAttribute("value"), OptElement.InnerText)
Else
Exit For
End If
Next OptElement
Not sure if 'exit try' is a good habit to get into compared to 'exit for' when looping, but I guess that's more opinion. In this example it should have the same effect, I would just make sure you don't intend to run any more code in the try...catch block at that point.
I appreciate the suggestions, I would agree that these are definitely more refined methods to accomplish my goal.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|