Storing Arrays in Variant Array

  1. 4 years ago

    Jordan D

    2 Mar 2014 Pre-Release Testers, Xojo Pro

    I'd like to store several string arrays for use later on in the Program. Trying to use Variant(), but not getting the results I expect.

    dim strArray() as string
    dim var() as variant

    While (something)
    // Stuff
    strArray.Append data
    wend

    var.append strArray
    redim strArray(-1)

    Somewhere else...

    dim s() as string
    s = var.pop

    What's the best way to store an array of arrays? Then retrieve them later.

    Thanks, JD

  2. Eli O

    is not verified 2 Mar 2014 Europe (Berlin, Germany)

    This line empties you're array:

    redim strArray(-1)

    Delete it and it will run properly.

  3. Kem T

    2 Mar 2014 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    The problem is, you are storing a reference to your string array, not a copy, so when you later clear it with the redim, you are clearing the original array.

    If you want a brand new array, do something like this instead:

    strArray = Array( "" )
    redim strArray( -1 )
  4. Norman P

    2 Mar 2014 Xojo Inc https://guykawasaki.com/the_ar...

    @Jordan D I
    What's the best way to store an array of arrays? Then retrieve them later.

    Quite literally - don't
    Design a class intended to hold your data and use that instead

    Then make an array of those

    You'll be better off in the long run

  5. last week

    Thanks Norman . . . needs a trick: if you have a two dimensional array in the class, you can't redimension the array from your primary code. You need to put a method in the class that redimensions the array:

    two dimensional array in the class:

    redim beamSeries(beamSeries.ubound).series(ubound(beamSeries(beamSeries.ubound).series,1)+1,2)

or Sign Up to reply!