- May 21, 2001
- 26,200
- 4,871
- 126
I'm starting to make the switch from VB6 to VB.NET. I have one big headache so far: lack of control arrays. Advice and articles that I read try to give you a way to mimic control arrays, but that just seems bad practice to do so (and they haven't worked for me either).
My biggest problem is trying to work with many controls on a form. For example, I need 500 textboxes with text that depends on data in a computer file. In VB6 that took only 4 lines to do a loop, read the file, and update the textbox's text. How do I do it in .NET?
So far, my searches have come up with things like this:
But that too just gives me errors or warnings. Usually, it is something like "Object reference not set to an instance of an object." But depending on the exact use, I've seen many other problem messages.
Is there a proper way to refer to a control by number such as TextBox1, TextBox2, TextBox3, ..., TextBox500? I'm using VB 2010 Express if it matters.
Thanks
My biggest problem is trying to work with many controls on a form. For example, I need 500 textboxes with text that depends on data in a computer file. In VB6 that took only 4 lines to do a loop, read the file, and update the textbox's text. How do I do it in .NET?
So far, my searches have come up with things like this:
Code:
Put calls to this in a loop:
Sub changeText(ByVal str As String, ByVal txt As String)
Dim ctl As Object
For Each ctl In Controls
If TypeOf ctl Is Button Then
If DirectCast(ctl, Button).Name = str Then
DirectCast(ctl, Button).Text = txt
End If
End If
Next
End Sub
Is there a proper way to refer to a control by number such as TextBox1, TextBox2, TextBox3, ..., TextBox500? I'm using VB 2010 Express if it matters.
Thanks
Last edited:
