Over the weekend for the second time in about three weeks a teacher asked my about creating arrays of controls in Visual basic .NET. Interestingly enough both teachers were interested in doing this to create a Jeopardy style game program. And why not? Clearly an array is the way to go. Now in Visual Basic 6.0 and earlier this was ridiculously easy to set up. In fact as a teacher teaching VB 6 I had students creating control arrays accidently at all the wrong times. With the advent of the .NET platform and the changes that went into making Visual Basic .NET a real honest to goodness object oriented programming language some of this ease of creation went away. Bummer.
Now it turns out that having control arrays (or more correctly arrays of controls) is not that difficult in Visual Basic .NET or even in C# for that matter. You do have to think about what you are doing though. On the plus side I see this different way of doing things as offering more opportunities for teaching and learning. No really. This can be a good thing. But of course the first thing I had to do was to figure things out myself. Fortunately for me I had access to the development team while VB .NET was still in beta. They were quite patient in explaining things to me that in hind sight I could have (perhaps should have) figured out myself. I’m grateful for their help. Does that help others? Not so much. On the other hand I did write up what I learned so I could share it with others. First with my students and these days with teachers.
I posted an article on creating control arrays using Visual Basic .NET and C# on my personal web site. If you are interested in learning how to do this for yourself I invite you to check out the article. It focuses more on implementation than going deeply into the concepts. As I read it today I realize that I should really add some more details to that document. If you have suggestions on what I should include please leave them in the comments here.
Oh and if you are interested in combining arrays of controls and creating custom controls check out Simon - An OOP Project for Visual Basic .NET And if you build a Jeopardy style game program let me know. I’d love to see it.