1. Home
  2. Computing & Technology
  3. Visual Basic
Dan Mabbutt
Dan's Visual Basic Blog

By Dan Mabbutt, About.com Guide to Visual Basic

Easily the most popular single topic at About Visual Basic

Saturday May 31, 2008

Whatever Happened to Control Arrays?

Years ago, I received the first of a continuing stream of emails asking this question. The problem is that one of the very popular features of VB6, Control Arrays, disappeared as part of the massive technoquake that is .NET. And a lot of people really miss it! I eventually published seven seperate articles about it. They're all listed in the last one of the series:

VB.NET: What Happened to Control Arrays!!! (Part VII)

I actually thought I had heard the end of this since I haven't received an email about it for several months. But Bruce Gordon, (check out his page The VB Programmer) sent me an email describing his favorite way to accomplish what he describes as a VB.NET 'control array'. His code seems to be a subset of the techniques that have been recommended by others, including Microsoft: Control Arrays for Visual Basic 6.0 Users.

This illustrates a fundamental principal of VB.NET: There are a gazillion ways to do just about anything and what you call it is often a matter of choice. Bruce admits that his technique doesn't satisfy many of Microsoft's definitions (see below) but he wrote that it works well for him.

You can review Bruce's recommendations in his own words here: The Bruce Gordon Control Array

For those who didn't use the VB6 control array, Microsoft's documentation states that they should have these features:

  • Iterating Through Controls
    VB6 had the ability to iterate through a group of controls using the Index property. For example, to clear the text of all TextBox controls in a control array, you could loop through the control array using the Index property as a loop variable. If Text1 was a TextBox control array, the code would look something like this:
    For i = 0 To Text1().UBound
    Text1(i).Text = ""
    Next
  • Siting on different Frame controls
    Controls in a single control array could be sited on different containers. For example, TextBox controls contained on two different Frame controls could be part of the same control array.
  • Adding Controls at Run Time
    Controls could be added to a control array at run time using the Load statement.
  • Adding Event Handlers at Run Time
    When you added a control to a control array at run time, the new controls events were automatically handled by the events for the control array.

VB6 control arrays were easy to create (Just add a second component with the same name and VB6 would politely ask if you were trying to create a control array.) and oh so very useful. Why couldn't Microsoft have thrown us a bone on this one?

Comments
June 4, 2008 at 2:33 pm
(1) PZI says:

The way I use control arrays in VB6 is to use an Enum for the various values of the Index. This allows me to make the code a bit more readable; unfortunately, it’s awkward to do using the proposed substitute method in VB.NET.

Sigh!

July 28, 2008 at 11:28 pm
(2) dazvenginzks says:

I’ve recently joined and wanted to introduce myself :)

October 8, 2008 at 8:29 pm
(3) EveSucher says:

Can’t find the right place to buy Viagra?
Aware of fraud or poor medications?
Visit Canadian Health&Care Mall and you won’t regret!
High-quality Viagra, Cialis and other medications:

Buy now high quality medications from the superb online pharmacy!

Secure and confidential purchase, instant shipping worldwide!

November 8, 2008 at 8:44 pm
(4) .net newbie says:

Hi, I have been also missing the VB6 control arrays. I have read and read and read about the subject but still haven’t found a solution for my problem. I admit I am no professional or even mid-class programmer but I like to make some of my ideas into applications. So: One of the things I did the most in vb6 is:
Having a set of optionbuttons (now named Radiobuttons) and according to which one was pressed, executing an activity, eg:

For i = 1 to 3
if option1(i).Checked = True Then
msgbox(”Option ” & i & ” was selected.”)
next i

I would like to do the same in VS2008 but the huge code I discovered in related articles intimidated me, mostly because I don’t understand what it does. Is there a simpler and clearer solution (code) for my problem?

Thank you

December 1, 2008 at 4:01 pm
(5) Rusysuede says:

I am here at a forum newcomer. Until I read and deal with the forum.
Let’s learn!

August 13, 2009 at 1:47 pm
(6) FatteGefe says:

This look interesting,so far.
If there are any real people here looking to network, leave me a post.
Oh, and yes I’m a real person LOL.

Peace,

August 13, 2009 at 5:09 pm
(7) visualbasic says:

I’m certainly a real person.

Did you notice that I consolidated all of the “Control Array” articles in a single download?

http://visualbasic.about.com/od/quicktips/qt/ctrlarrsumm.htm

November 22, 2009 at 11:17 am
(8) Esomiamum says:

thanks a lot for this

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.