VB.net/VB 2005 Using multiple types in an array


I am working in Visual Studio 2005.
Is it possible to use mutliple types with the same array

eg Dimm arr(10) as Object

arr(0) = "Hello"
arr(1) = False
arr(2) = 23
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jens FiedererTest Developer/ValidatorCommented:
yes.   you want to use just one "m" in a dim.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for that!
The dimm was a typo.
Appreciate the quick answer!
Jens FiedererTest Developer/ValidatorCommented:
Note, though, that this is really a case of using subclasses, and everything being a subclass of Object.

If you declared

dim arr(10) as Shape

And Circle, Square, and Triangle all interited from Shape, you could put
Circles Squares and Triangles in arr ... but not, for example, an arraylist.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
I think I understand your last comment.
I just want to be able to eg do the following
Dim A(2) As Object
A(0) = "Tree"
A(1) = xlYesNoGuess.xlYes
A(2) = 3456376

I am assuming that this is okay.

Jens FiedererTest Developer/ValidatorCommented:
That will WORK, but it is dangerous.

Later, when you reference A(2)...and maybe expect to find a string rather than a number...you might blow up.

It is generally good programming practice to make the type of the Array as specific as possible, to minimize the chance of a type mismatch in the future.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.