Need help with code
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
Hi guys I am have some issues with a code. The code is retreving a peice of code from a web site
I am using the code to retrive the output
site code
now the problem os that the C0 can be diferent things like a,b,c,d,e,f and tose are from 1 to 20
It would be nice if the text box actuly only showed the selected one in this example the textbox.text would be equal to A1
I am using the code to retrive the output
Code: Select all
textbox.text = WebBrowser2.Document.GetElementById("OutputHistory").InnerHtml
site code
Code: Select all
now i want to retreve just the C0 in the code to a text box in visual <td width="25%">
<select size="4" name="OutputHistory" id="OutputHistory" style="height:300px;width:100%;">
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value="">C0</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option selected="selected" value="A1">A1</option>
now the problem os that the C0 can be diferent things like a,b,c,d,e,f and tose are from 1 to 20
It would be nice if the text box actuly only showed the selected one in this example the textbox.text would be equal to A1
Last edited by skyteam on Tue Oct 23, 2012 4:08 am, edited 1 time in total.
Try this code:
Code: Select all
This will get the text in the 9th <option> tag (in this case, A1). However, if you want to get C0, use this:Dim outputhistory As HtmlElement = WebBrowser1.Document.GetElementById("OutputHistory")
Dim optionList As HtmlElementCollection = outputhistory.GetElementsByTagName("option")
TextBox1.Text = optionList(8).InnerText
Code: Select all
Dim outputhistory As HtmlElement = WebBrowser1.Document.GetElementById("OutputHistory")
Dim optionList As HtmlElementCollection = outputhistory.GetElementsByTagName("option")
TextBox1.Text = optionList(4).InnerText
this works grate now if i have more the one i want it to always get the selected one any way of doing that? hey cool tu est francais = ) moi aussi je vien du quebec
Sorry, I don't understand what you mean by that. The first bit of code I gave you will return the value of the selected item, as long as there are 9 <option> tags and that the selected one is last.
Do you mean the number of tags will vary?
Do you mean the number of tags will vary?
skyteam wrote:i want it to always get the selected one any way of doing that?You can add this code so it gets the selected text:
Code: Select all
Dim strIndex As String = outputhistory.GetAttribute("selectedIndex")
Dim index As Integer = Integer.Parse(strIndex)
Dim selectedText As String = optionList(index).InnerText
TextBox1.Text = selectedText
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023