Solved

Array variable setup

Posted on 2008-06-13
7
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Accepted Solution

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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