How to use variable variable name?

I have 100 textbox in my form. Their names are tb1, tb2, ... tb100

I need to retrieve the values from these 100 textboxes.

How can I use a loop to address these 100 textboxes name



Answer this question

How to use variable variable name?

  • KoryS

    for each currentControl as Control in Me.Controls

    if TypeOf(currentControl) Is TextBox then

    Dim theTextBox as TextBox = currentControl

    'do your stuff with theTextBox as it has now been made the same textbox as the textbox on the control

    end if

    next



  • Jesse Motes

    Try this:
    Dim values(99) As String
    For ix As Integer = 1 To 100
    Dim txt As TextBox = Me.Controls("tb" + CStr(ix))
    If txt IsNot Nothing Then values(ix-1) = txt.Text
    Next



  • How to use variable variable name?