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.
5 posts Page 1 of 1
Contributors
User avatar
skyteam
Member
Member
Posts: 27
Joined: Thu Apr 28, 2011 1:27 am

Need help with code
skyteam
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
Code: Select all
textbox.text = WebBrowser2.Document.GetElementById("OutputHistory").InnerHtml


site code
Code: Select all
 <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 i want to retreve just the C0 in the code to a text box in visual
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.
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: eed help with code
comathi
Try this code:
Code: Select all
Dim outputhistory As HtmlElement = WebBrowser1.Document.GetElementById("OutputHistory")
        Dim optionList As HtmlElementCollection = outputhistory.GetElementsByTagName("option")
        TextBox1.Text = optionList(8).InnerText
This will get the text in the 9th <option> tag (in this case, A1). However, if you want to get C0, use this:
Code: Select all
Dim outputhistory As HtmlElement = WebBrowser1.Document.GetElementById("OutputHistory")
        Dim optionList As HtmlElementCollection = outputhistory.GetElementsByTagName("option")
        TextBox1.Text = optionList(4).InnerText
User avatar
skyteam
Member
Member
Posts: 27
Joined: Thu Apr 28, 2011 1:27 am

Re: eed help with code
skyteam
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
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Need help with code
comathi
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?
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Need help with code
mandai
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
Return to “Coding Help & Support”