Results 1 to 8 of 8

Thread: [RESOLVED] quick arry question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Resolved [RESOLVED] quick arry question

    Rather then adding arry(0) for all 10 member sof the arry i was trying to think of a work around.
    any thing obviously wrong with this?

    Code:
        Private Sub arryTextBox(ByVal root As Control)
    
            For Each ctrl As Control In root.Controls
                For x As Integer = 0 To arry.Count - 1
                    arry(x) = CType(ctrl, TextBox).Text
                Next
            Next ctrl
    
        End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: quick arry question

    Code:
        Private Sub arryTextBox(ByVal root As Control)
            For Each ctrl As Control In root.Controls
                If TypeOf ctrl Is TextBox Then
                    For x As Integer = 0 To arry.Count - 1
                        arry(x) = Me.Controls("TextBox" & x.ToString()).Text
                    Next
                End If
            Next ctrl
        End Sub
    Returns nullreference. But i renamed the first instance of the textbox to 0 to avoid this.

  3. #3
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: quick arry question

    Perhaps, if you told us what exactly you are trying to achieve we could offer you better help.
    As for the null reference it's probably due to the fact that your array had not been properly initialized or no control with the name TextBoxN where N is a some number exist.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: quick arry question

    Sorry cicatrix. Lets try to explain better.

    20 textbox controls, Need to loop through these to get there values to add to an array.

    arry(0) = textbox1.text
    arry(1) = textbox2.text

    etc just seems a long way to go about it.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: quick arry question

    Very strange, it works now............. Maybe a typo in the textbox

  6. #6

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: [RESOLVED] quick arry question

    Do you mean list of string? when you say list....

  8. #8
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: [RESOLVED] quick arry question

    I mean
    Code:
    Dim arry As New List(Of TextBox)
    Or

    Code:
    Dim arry As New Dictionary(Of String, TextBox)

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