Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Array variable setup

Posted on 2008-06-13
7
Medium Priority
?
188 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 34

Author Comment

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

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 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 34

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 34

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

972 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