...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.


Visual Basic

Control Arrays and .NET, bundled with a lack of support.

Monday, February 18, 2008 in Technical Articles (Views: 6389)


You know, Microsoft has the uncanny ability to take something good, remove it (sometimes replacing it with an inferior concept), and call that "an upgrade".

Why are control arrays so special? Well, the reason Card Magic was written in VB6 is a dead giveaway - I have a 54 card deck (jokers included) and want to be able to programmatically control all 54 cards at once (say, change their faces)...

This is the code required for VB6:

for i=1 to 54




So, really, we have 2 lines of code here. One that changes the card, so it knows what card is actually playing, and a second line that takes the picture for the card. Also, do remember that the -1 after the controlname is that the index starts at 0, not 1.

I won't write out the .NET equivalent, but will outline the steps..

1. Import the System.Collections.CollectionBase namespace

2. Modify the form so that only it can mod itself (aka Private)

3. Create a button for each control (and add a line for each property you want to modify)

4. Add the form to the page

NOW - you can modify the controls.

I got less in about 30+ lines of .NET code than 2 lines of VB6 code - DAMNIT BILL!

Here's the catch

If you look in .NET and reference the VB6 compatibility library, you can find objects that function somewhat like old school control arrays, but not quite.

If you don't believe me, create an application in VB6 with a control array, and THEN use the "seamless" VB.NET upgrade wizard. The code you get in the new "upgraded version" of the app is ugly at best, and in theory works.

So what's the problem with Compatibility Libraries?

1. Microsoft will not guarantee the compability components (they say there is 95% accuracy in its code conversion).

2. Microsoft will not guarantee these compatibility components will actually be supported

3. Microsoft says even though the components exist, you aren't really supposed to use them.

So, this is the typical business model of a company that has too much money on its hands. We will develop a product that works somewhat, hype it with the actual product, and not support it.

I wrote Card Magic in VB6 because of control arrays - .NET has some nice things in it, but I can't believe they replaced something that good with something that lousy.


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.