Solved

Array variable setup

Posted on 2008-06-13
7
175 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views 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 Access…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…

760 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

19 Experts available now in Live!

Get 1:1 Help Now