Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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

Hi

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
etc
0
Murray Brown
Asked:
Murray Brown
  • 3
  • 3
1 Solution
 
Jens FiedererCommented:
yes.   you want to use just one "m" in a dim.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for that!
The dimm was a typo.
Appreciate the quick answer!
0
 
Jens FiedererCommented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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.

Thanks
0
 
Jens FiedererCommented:
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.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now