Trying to parse some text from a html source file

Archolm

Member
Joined
Feb 9, 2011
Messages
6
Programming Experience
Beginner
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim StrInput As String = Display.Text
        Dim firstInteger, secondInteger As Integer

        firstInteger = StrInput.IndexOf("ad_list_link", 0)
        secondInteger = StrInput.IndexOf("ad_list_link", firstInteger)


        FirstAd.Text = StrInput.Substring(secondInteger + 95, StrInput.IndexOf("ad_list_link"))

        secondInteger = StrInput.IndexOf("userdata", 0)
        FirstAd.Text = StrInput.Remove(secondInteger, StrInput.IndexOf("</html>"))
    End Sub

Anyone care to comment as to what the problem could be?

I need to string z from a webpage source file but having trouble cutting the code around it away.
 
firstInteger = StrInput.IndexOf("ad_list_link", 0)
secondInteger = StrInput.IndexOf("ad_list_link", firstInteger)
Searching for same text starting where you found that text will only get you the same index result. You can put a breakpoint in and inspect the values to see for yourself. If you want to find a second occurance you will have to start searching after the first found index, ie at minimum from [first+1] but it would also make sense to start at [first + length of matched string].
FirstAd.Text = StrInput.Substring(secondInteger + 95, StrInput.IndexOf("ad_list_link"))
Given that Substring method parameters means start and length, does that logic really apply well? Also, given that you as last argument use an expression you have already performed before and already have the result for, shouldn't that be used instead of doing the same thing over again? Anyhow, try to get the logic right first by writing in down in plain sentences, you can use these as comments in code to explain what the code is supposed to do. And again, use break points to debug that you are getting the results you expect.
Dim firstInteger, secondInteger As Integer
The highlighted part is rather unnecessary, adding data type name in the variable name is just adding characters to the code. The data type information is declared and and can also be read any time in IDE, including by hovering the variable.
 
Back
Top