matbor
February 10th, 2009, 06:58 PM
Hi all, very new to Visual Basic and this forum so not sure if this is the right area to post.
I am trying to write a small program to pull some data from a website and display it.... it will do a whole lot more in the future, but at this stage this is far as I have gotten.
Basically my problem is I have now created TAB's with the form and moved all the buttons etc into the tabs and now my code isn't working, keeps coming up with the following error
"Object reference not set to an instance of an object."
I have google'd and pulled my hair out but can't work out how to fix it.
Here is the code I have so far (see below), if u scroll down to the part " Me.Controls.Item("TextBox" & i).Text() = datadisplay" this is where it throws the error.
I have also attached the project in a rar file.
Thx
Matt.
----
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim websiteurl
' get URL from text box
websiteurl = txtWebpage.Text
' open URL in webbrowser
WebBrowser1.Navigate(websiteurl)
Debug.Print(websiteurl)
' run the grab datascript and display
Button2.Visible = True
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim searchtext, datadisplay, pos_start, pos_end, needtoreplace, lastcomma, nextcomma
' display RAW html in box
rtbDisplayData.Text = WebBrowser1.DocumentText()
' let the variable = the raw html
searchtext = WebBrowser1.DocumentText()
' find first line of table
pos_start = InStr(searchtext, "rowleftcolumn")
' add 25 to get to start of data
pos_start = pos_start + 25
' starting at beginning of first line in table find end of line
pos_end = InStr(pos_start, searchtext, "</tr>")
pos_end = pos_end - pos_start - 6
' clear all the spaces and put a commar in between the data
searchtext = Mid(searchtext, pos_start, pos_end)
needtoreplace = "</td>" & vbLf & Space(2) & "<td>"
searchtext = Replace(searchtext, needtoreplace, ",")
searchtext = searchtext & ","
' display in Extracted data box
RichTextBox1.Text = searchtext
Debug.Print(searchtext)
'Now display each information in each individual textbox
lastcomma = 1
nextcomma = 1
For i = 1 To 14 Step +1
nextcomma = InStr(lastcomma, searchtext, ",")
datadisplay = Mid(searchtext, lastcomma, (nextcomma - lastcomma))
' display information in each textbox
Me.Controls.Item("TextBox" & i).Text() = datadisplay
lastcomma = nextcomma + 1
' debugs
Debug.Print("______")
Debug.Print("step " & i)
Debug.Print("textbox" & i & ".text")
Debug.Print(datadisplay)
Debug.Print("nextcomma position " & nextcomma)
Debug.Print("lastcomma position " & lastcomma)
Next i
'Change the Compass points.
If TextBox7.Text = "N" Then rbNorth.Select()
If TextBox7.Text = "E" Then rbEast.Select()
If TextBox7.Text = "S" Then rbSouth.Select()
If TextBox7.Text = "W" Then rbWest.Select()
End Sub
End Class
I am trying to write a small program to pull some data from a website and display it.... it will do a whole lot more in the future, but at this stage this is far as I have gotten.
Basically my problem is I have now created TAB's with the form and moved all the buttons etc into the tabs and now my code isn't working, keeps coming up with the following error
"Object reference not set to an instance of an object."
I have google'd and pulled my hair out but can't work out how to fix it.
Here is the code I have so far (see below), if u scroll down to the part " Me.Controls.Item("TextBox" & i).Text() = datadisplay" this is where it throws the error.
I have also attached the project in a rar file.
Thx
Matt.
----
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim websiteurl
' get URL from text box
websiteurl = txtWebpage.Text
' open URL in webbrowser
WebBrowser1.Navigate(websiteurl)
Debug.Print(websiteurl)
' run the grab datascript and display
Button2.Visible = True
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim searchtext, datadisplay, pos_start, pos_end, needtoreplace, lastcomma, nextcomma
' display RAW html in box
rtbDisplayData.Text = WebBrowser1.DocumentText()
' let the variable = the raw html
searchtext = WebBrowser1.DocumentText()
' find first line of table
pos_start = InStr(searchtext, "rowleftcolumn")
' add 25 to get to start of data
pos_start = pos_start + 25
' starting at beginning of first line in table find end of line
pos_end = InStr(pos_start, searchtext, "</tr>")
pos_end = pos_end - pos_start - 6
' clear all the spaces and put a commar in between the data
searchtext = Mid(searchtext, pos_start, pos_end)
needtoreplace = "</td>" & vbLf & Space(2) & "<td>"
searchtext = Replace(searchtext, needtoreplace, ",")
searchtext = searchtext & ","
' display in Extracted data box
RichTextBox1.Text = searchtext
Debug.Print(searchtext)
'Now display each information in each individual textbox
lastcomma = 1
nextcomma = 1
For i = 1 To 14 Step +1
nextcomma = InStr(lastcomma, searchtext, ",")
datadisplay = Mid(searchtext, lastcomma, (nextcomma - lastcomma))
' display information in each textbox
Me.Controls.Item("TextBox" & i).Text() = datadisplay
lastcomma = nextcomma + 1
' debugs
Debug.Print("______")
Debug.Print("step " & i)
Debug.Print("textbox" & i & ".text")
Debug.Print(datadisplay)
Debug.Print("nextcomma position " & nextcomma)
Debug.Print("lastcomma position " & lastcomma)
Next i
'Change the Compass points.
If TextBox7.Text = "N" Then rbNorth.Select()
If TextBox7.Text = "E" Then rbEast.Select()
If TextBox7.Text = "S" Then rbSouth.Select()
If TextBox7.Text = "W" Then rbWest.Select()
End Sub
End Class