Solved

Array variable setup

Posted on 2008-06-13
7
181 Views
Last Modified: 2010-04-21
I want to create a multi dimential dynamic array variable called Status() as shown below.  

Status(Row, MorN, NoOrState, DateModYN)

Sub Test1() works okay. But Test2() errors at:  ReDim Preserve Status1(2, 2, 2, 2) '*********

How can I correct this?

Thank you.


Sub test1()
 
    Dim Status1() As String
    ReDim Preserve Status1(1, 2, 2, 2)
 
    Status1(1, 1, 1, 1) = "101"
    Status1(1, 2, 1, 1) = "N"
    Status1(1, 1, 2, 1) = "No"
    Status1(1, 1, 1, 2) = "ModY"
 
    MsgBox Status1(1, 1, 1, 1)
    MsgBox Status1(1, 2, 1, 1)
    MsgBox Status1(1, 1, 2, 1)
    MsgBox Status1(1, 1, 1, 2)
 
End Sub
 
Sub test2()
 
    Dim Status1() As String
    ReDim Preserve Status1(1, 2, 2, 2)
 
    Status1(1, 1, 1, 1) = "101"
    Status1(1, 2, 1, 1) = "N"
    Status1(1, 1, 2, 1) = "No"
    Status1(1, 1, 1, 2) = "ModY"
 
    MsgBox Status1(1, 1, 1, 1)
    MsgBox Status1(1, 2, 1, 1)
    MsgBox Status1(1, 1, 2, 1)
    MsgBox Status1(1, 1, 1, 2)
 
    ReDim Preserve Status1(2, 2, 2, 2) '*********
 
    Status1(2, 1, 1, 1) = "102"
    Status1(2, 2, 1, 1) = "N1"
    Status1(2, 1, 2, 1) = "No1"
    Status1(2, 1, 1, 2) = "ModY1"
 
    MsgBox Status1(2, 1, 1, 1)
    MsgBox Status1(2, 2, 1, 1)
    MsgBox Status1(2, 1, 2, 1)
    MsgBox Status1(2, 1, 1, 2)
 
End Sub

Open in new window

0
Comment
Question by:Mike Eghtebas
  • 4
  • 3
7 Comments
 
LVL 75
ID: 21783483
What is the error Mike ?

mx
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 21783496
Run-time error 9
Subscript out of range.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 21783504
I want to increment ---v
                      Status(Row, MorN, NoOrState, DateModYN)

The others (MorN, NoOrState, DateModYN) will remain 2 always.

Mike
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 21783513
This might be it - from the Help File **** --- ****:

"If you use the Preserve keyword, you can resize only the **** last array dimension *** and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.

ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)

Similarly, when you use Preserve, you can change the size of the array only by changing the upper bound; changing the lower bound causes an error."
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 21783905
So, instead of Status(Row, MorN, NoOrState, DateModYN) I can have:

Status(MorN, NoOrState, DateModYN, Row)

Because I will need to resize only Row. I will try it on Monday.

Thanks,

Mike
0
 
LVL 33

Author Closing Comment

by:Mike Eghtebas
ID: 31467119
Thank you very much.
0
 
LVL 75
ID: 21794963
you're welcome Mike ....

mx
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now