CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    1

    Question A little help needed with textboxes and tabs!

    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.

    ----

    Code:
    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
    Attached Files Attached Files
    Last edited by HanneSThEGreaT; February 11th, 2009 at 12:38 AM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured