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

Clif's Code

By Dan Mabbutt, About.com

Clif Gay was kind enough to supply an example of his own using this idea. Clif's example is a great example of some advanced coding in several other ways too, so it's worth paying attention to.

Clif's code demonstrates a ComboBox control array with five elements. Clif added code to each "Designer.vb" initialization routine like this:

'ComboBox0
'
Me.ComboBoxArray1.SetIndex(Me.ComboBox0, CType(0, Short))
<other initialization>

'ComboBox1
'
Me.ComboBoxArray1.SetIndex(Me.ComboBox1, CType(1, Short))
<other initialization>

Notice how the index value in both the CType function and the name of the control are changed in each initialization.

When the form designer in VB.NET and VBE are closed, the "Designer.vb" file is rewritten and, since the form designer considers everything to be internal code, statements are even resorted and moved. Don't expect the statements you add to even be in the same location.

The example helpfully provides two different ways of doing the same thing ... with and without the use of the compatibility.vb6 namespace and VB.NET control arrays. So one lesson you should take away with you is that there still isn't any absolute requirement to use VB6 style control arrays. You can still do whatever you need to do without them. (That's one reason Microsoft decided not to support them in .NET.)

Click here to download all of the examples used in this article.

Explore Visual Basic
By Category
About.com Special Features

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

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. VB.NET: What Happened to Control Arrays!!! (Part VII)

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

All rights reserved.