Set a certain range of textboxes to be invisible (vb)

I am relatively new to VB.net and I would like to hide all textboxes that are not in a certain value. My textboxes' IDs are from 1-30 (e.g. TextBox1, TextBox2, ...).

An example of my problem is this:

If the length of a string is 7 -> hide TextBoxes from 8-30 (leave only 7 textboxes).

Thanks in advance


  • for i=8 to 30
                Dim c as string = "Textbox" & i.toString
                DirectCast(Me.Controls.Find(c, False)(0), TextBox).Enabled= False

    Let's cycle between 8 and 30, create a string c containing the control name by combining "textbox" and i. Find the control whose name is c among the controls in the form, do not recurse, and select the first occurrence (0). Set the property of such control to Enabled = false.