Results 1 to 3 of 3

Thread: question to set up an array of controls or not??

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    question to set up an array of controls or not??

    Ok as I have posted before I am a newbie to this so please be gentle...

    I have a tabbed form with numerous text boxes on, now some of these text boxes are related to one another whilst others aren't.

    e.g.
    tab1
    [MH1] [MH2] [MH3] [MH4] [MH5]
    [MH6] [MH7] [MH8] [MH9]
    [MH10]

    tab2
    [MH11] [MH12] [MH13] [MH14] [MH15]
    [MH16] [MH17] [MH18] [MH19]
    [MH20]



    MH1 TO MH10 are all related as are MH11 TO MH20, however MH1 to MH5 form a line of output to a file, MH6 to MH9 form the next line and MH10 the next. MH11 to MH15 form the next line of output and so on til MH20.

    Question: Is it best to set up a array of text boxes for each seperate line of output?? Also what is the best way to read each/all these text boxes to check the data that has been input?

    regards,

    Matt

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: question to set up an array of controls or not??

    It is easier to create these at run time, although you need to work out their positions.

    Code:
        Dim TB(10) As TextBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MyBase.Load
    
            For i As Integer = 0 To 10 - 1
                'Make a new textbox
                TB(i) = New TextBox
                'Set the textbox name
                TB(i).Name = "TB" & i.ToString
                'Add a handler for the text changed event
                AddHandler TB(i).TextChanged, AddressOf HandleAllTextBoxes
                'Add the textbox to the form
                Me.Controls.Add(TB(i))
                'Arrange text boxes as three rows of 5, 4 and 1
                'You can probably write this bit more efficiently
                TB(i).Left = 5
                If i = 0 Then
                    TB(i).Top = 5
                ElseIf i = 5 Then
                    TB(i).Top = TB(0).Top + TB(i).Height + 5
                ElseIf i = 9 Then
                    TB(i).Top = TB(0).Top + TB(i).Height * 2 + 5 * 2
                Else
                    TB(i).Top = TB(i - 1).Top
                    TB(i).Left = TB(i - 1).Right + 5
                End If
            Next
    
            'To examine each textbox, use a loop like this
            For i As Integer = 0 To TB.GetUpperBound(0) - 1
                'Check the contents of each box TB(0) to TB(n)
            Next
    
        End Sub
    
        Private Sub HandleAllTextBoxes(ByVal sender As Object, ByVal e As System.EventArgs)
            'Do stuff
            MessageBox.Show("Textbox " & CType(sender, TextBox).Name.ToString & " was changed.")
        End Sub
    You can create a sub like this for each tab, or have one sub that creates and handles all textboxes on all tabs.
    Last edited by Bulldog; Apr 17th, 2007 at 05:24 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: question to set up an array of controls or not??

    Thanx for the help will give it a try tommorow.

    regards,

    Matt

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