CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Location
    Mississauga, CANADA
    Posts
    199

    Alternative to dynamic variant arrays?

    The answer to this question may be really easy, but my brain is turning to mush with the learning curve moving to .NET.
    .
    We are moving a vb6 COM dll to vb.net. There is a LARGE amount of dynamic, compund arrays declared as follows in vb6:
    .
    dim aMyArray() as Variant
    then later in the code it is changed as follows:
    REDIM aMyArray(x,12)
    with x being the number of records returned in a given table query. The 12 represents KNOWN (but mixed) datatypes ie... string, date, etc...
    Q. Can each sub element (0-11) be initialized to their respective datatypes? If so, where would they be initialized and how?
    .
    Thanks
    Paul
    Paul

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    No, they have to be Dim'ed the same, so the best you can do is Dim them as Object.

  3. #3
    Join Date
    Sep 2003
    Location
    MO
    Posts
    15
    Can't you use a structure? That way each dimension represents a different variable type.

    Code:
    Structure WordsNumbers
        Dim word as string
        Dim number as integer
    end structure
    Then you can dimension an array as that type
    Code:
    dim array(10) as WordsNumbers
    That way you can call array(1).word and put a string in it and
    array(1).number and put a integer in it etc.

    Another example

    Code:
    Structure People
       Dim age as double
       Dim name as string
       Dim lastname as string
    end structure
    Code:
    dim Person(10) as People
    Code:
    Person(1).age = 30
    Person(1).name = "John"
    Person(1).lastname = "Doe"
    Last edited by Adovid; September 25th, 2003 at 02:06 PM.

  4. #4
    Join Date
    Apr 2001
    Location
    Mississauga, CANADA
    Posts
    199
    I'll try that and let you know.
    Thanks
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured