Dynamic Variable Array Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Keriana30
    New Member
    • Nov 2007
    • 7

    Dynamic Variable Array Issue

    I need to base a variable array using a variable. For example,

    ReDim pstrDepSSN(pint RecordCount) as string

    The only way to do this is with the ReDim statement but it doesn't permit me to declare the variables as Static so that they hold their values. And if I declare the variables as Static like this

    Static pstrDepSSN(pint RecordCount) as string

    then I'm not using ReDim so it requires a constant expression rather than the variable pintRecordCount to be used in the parentheses. Does anyone know of a fix or a way to declare Static Dynamic Variable Arrays?

    Appreciate any help. Thank you,

    Keriana30
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by Keriana30
    then I'm not using ReDim so it requires a constant expression rather than the variable pintRecordCount to be used in the parentheses. Does anyone know of a fix or a way to declare Static Dynamic Variable Arrays?

    Appreciate any help. Thank you,

    Keriana30
    declare it as a public array, in any module's declarations

    public Arr() as double

    then, when you change something in any sub, in any module, it'll be kept.

    HTH

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Though I haven't tried, you might find that the "empty brackets" technique also works for Static variables. However, I suspect it won't.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Actually, I dint get you clearly...

        I guess, you want to Declare an Array, and then ReDim with a Variable Value..

        What you can do is in FormLevel , Declare a Variable as Variant.:

        Dim MyArr

        and then redim to whatever Variable value you want :

        ReDim Preserve MyArr(MyCounter )
        First Time, When you Redim, you may get an error(For Preserve), you have to keep a Flag for that and Redim,(With or Without Preserve)


        Let me know, if your requirement is something else....

        Regards
        Veena

        Comment

        Working...