Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Array variable setup

Posted on 2008-06-13
7
Medium Priority
?
186 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

719 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