[RESOLVED] [2008] Control Arrays in VB 2008
Quick question,
How do I do create control arrays in VB2008. In vb6.0 I was able to do
vb.net Code:
For i As Integer, 0 to 9, step 1
txtMSG(i).text = ("I am text box number: " + chr(i + 49))
Next
I need to be able to enumerate through a series of controls in this way.
Thanks
Brad Swindell
IT Manager
Electronix Systems C.S.A. Inc.
Re: [2008] Control Arrays in VB 2008
There is, but you have to change the way you think about it. There is no longer a way to create Control Arrays at design time... it has to be done at runtime... and it becomes and array of controls - jsut like any other array. If it's one type, like a button, you can use generics and make it a List (Of CommandButton). - or what ever else you need. And then in the constructor or the load, you have to figure out some way to load them into the array, list, what ever collection you use.
Something similar to this should work:
Code:
Private Shared _dataCols() As DataColumn = {New DataColumn("TrackCode", GetType(String)), New DataColumn("RaceID", GetType(Integer)), New DataColumn("RaceNumber", GetType(String)), New DataColumn("PostTime", GetType(Date))}
-tg
Re: [2008] Control Arrays in VB 2008
As tg says, arrays of controls are just like any other arrays in VB.NET.
vb.net Code:
Private textBoxes As TextBox()
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
Me.textBoxes = New TextBox() {Me.TextBox1, Me.TextBox2, Me.TextBox3}
End Sub
Re: [2008] Control Arrays in VB 2008
This article (series of articles) may be of interest:
http://visualbasic.about.com/b/2008/...sual-basic.htm
Re: [2008] Control Arrays in VB 2008
Here is a little example of a way you can do arrays in .net
Add 3 text boxes and execute this code under a button.
Code:
Dim whatever() As TextBox = {TextBox1, TextBox2, TextBox3}
Dim i As Integer = 0
'
For i = 0 To 2
whatever(i).Text = "simple " & i
Next
Re: [2008] Control Arrays in VB 2008
Thanks guys that works perfectly. Will this also work with timers?
Re: [2008] Control Arrays in VB 2008
Quote:
Originally Posted by BKSwindell
Thanks guys that works perfectly. Will this also work with timers?
As we have stated fairly clearly already, an array is an array, whatever it contains. All arrays work the same way.
Re: [2008] Control Arrays in VB 2008