|
-
Oct 12th, 2008, 07:59 AM
#1
Thread Starter
Lively Member
[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.
-
Oct 12th, 2008, 10:17 AM
#2
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
-
Oct 12th, 2008, 09:53 PM
#3
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
-
Oct 13th, 2008, 08:47 AM
#4
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
"It's cold gin time again ..."
Check out my website here.
-
Oct 13th, 2008, 10:49 AM
#5
Addicted Member
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
VS 2015 Pro
Windows 10 x64 Pro
-
Oct 13th, 2008, 02:57 PM
#6
Thread Starter
Lively Member
Re: [2008] Control Arrays in VB 2008
Thanks guys that works perfectly. Will this also work with timers?
-
Oct 13th, 2008, 03:37 PM
#7
Re: [2008] Control Arrays in VB 2008
 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.
-
Oct 13th, 2008, 04:28 PM
#8
Thread Starter
Lively Member
Re: [2008] Control Arrays in VB 2008
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|