Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating arrays in runtime (2003)

    The following code works

    Dim AcoountJournalHolder(1 To (1000)) As JournalHolder

    However I would really like to re-write the above as follows:

    Dim AcoountJournalHolder(1 To (EndRowMarker-2)) As JournalHolder

    Where EndRowMarker-2 is the number of JournalHolders I need.

    However when I run the above using the variable EndRowMarker I get the error "Constant expression required"

    I have tried writing:

    Const ConEndRowMarker as long = EndRowMarker
    'After I had found the value of EndRowMarker, to then use ConEndRowMarker in the array creation code . However this too failed.

    How can I get around this problem?

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Creating arrays in runtime (2003)

    <pre>Dim AcoountJournalHolder() As JournalHolder '
    'Then later in code REDIM it after the other variable is set
    Redim AcoountJournalHolder(1 To (EndRowMarker-2))</pre>


    Steve

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating arrays in runtime (2003)

    For further information JournalHolder is a Type containing 5 variables

    At the redim statement I get the error "array already dimensioned"

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating arrays in runtime (2003)

    Got it working

    Thanks

  5. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Creating arrays in runtime (2003)

    Was your error due to DIMming it "completely" with a range and then trying to REDIM it:
    <pre>Dim AcoountJournalHolder(1 To 1000) As JournalHolder</pre>

    instead of
    <pre>Dim AcoountJournalHolder() As JournalHolder</pre>


    Or was it something else?

    Steve

  6. #6
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating arrays in runtime (2003)

    It was that I had not changed

    Dim AcoountJournalHolder(1 To 1000) As JournalHolder

  7. #7
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Creating arrays in runtime (2003)

    That is a common mistake. You can only (as you have discovered) REDIM arrays that are created as "open arrays" of no explicit size. If you DIM it with an explicit size it can not be REDIMed.

    Steve

Posting Permissions

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