CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: A little help needed with textboxes and tabs!

    1) Please use CODE TAGS so we can read your mess.

    2) Most people never even HEARD of RAR files.

    3) You can loop thru a form's controls. Using the .Tag property could help...

    Code:
        Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    
            Dim t As New TextBox
            t = TextBox1
            t.Text = 4
            For Each c In Me.Controls
                If TypeOf (c) Is TextBox Then
                    MsgBox(c.ToString)
                End If
            Next c
        End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: A little help needed with textboxes and tabs!

    Welcome to the forums matbor!

    Can you tell us on which line precisely the error occurs &#191;

    Also, it would be best if you rather zip your project, instead of Rar

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