locked
Array element data types RRS feed

  • Question

  • Hello Group

     

    Is it possible to have data of more than one data type within the same array? I don't mean declaring the array as a Variant data type, which I believe would be slower and probably take up more space, but to actually declare the data types.

     

    Example:

    If I want to declare an array Customers(1000,50) where of the 50 elements 30 might be Strings, 10 Integers, 5 Decimal and 5 Boolean data types, can I specify this within the one array or is it necessary to declare four separate arrays CustsStr(1000,30) CustsInt(1000,10) etc.

     

    Sorry if this has already been answered, I'm a newbie!

     

    Cheers guys!

     

    Tuesday, July 3, 2007 8:50 AM

Answers

  • No you can't specify that in the array declaration. You can store different types of data in an array as long as they all derive from a common array element type. In this case that would be Object (there's no Variant type in VB anymore).

     

    If you want strong typing you could go with multiple different arrays as you suggested.

     

    But it really sounds like you'd want to create a Customer class with strongly typed fields to hold each value.

     

    Tuesday, July 3, 2007 10:01 AM