INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA three dimensional array of unknown size

VBA three dimensional array of unknown size

(OP)

I currently have three single arrays working but I would like to replace them with one 3 dimensional array. I have been trying without success for hours.

Here is the working code for the three arrays:

I need the code to achieve the same thing but using one 3 dimensional array instead of the three arrays I currently have.

I declare 3 global arrays
Private aOne() As Single
Private aTwo() As Single
Private aThree() As Double

I run this once for first size
ReDim aOne(1 To 1)
ReDim aTwo (1 To 1)
ReDim aThree(1 To 1)

I populate the 3 arrays and resize them
aOne(UBound(aOne)) = MyVariableOne
aTwo(UBound(aTwo)) = MyVariableTwo
aThree(UBound(aThree)) = MyVariableThree
ReDim Preserve aOne(1 To UBound(aOne) + 1)
ReDim Preserve aTwo (1 To UBound(aTwo) + 1)
ReDim Preserve aThree(1 To UBound(aThree) + 1)

I retrieve the values
Dim i As Long
For i = LBound(aOne) To UBound(aOne) - 1
msgbox aOne
msgbox aTwo
msgbox aThree
Next

RE: VBA three dimensional array of unknown size

First, arrays are 0 based, so why do you make them start with 1?
2. Array can be only one type, you have 2 arrays As Single and 1 array As Long. You need to decide what type of 3-D array you need.
3. To declare, use, redim, preserve, etc. multi-dimensional array, look here

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: VBA three dimensional array of unknown size

(OP)
hank you Andrzejek I will take a look and try to work it out.

RE: VBA three dimensional array of unknown size

From your example it looks like you need 2D array. If all data can be double, you can:
Redim Preserve anAllInOne(1 To 3, 1 To Ubound(anAllInOne, 2)+1)
You can resize only last dimension.

combo

RE: VBA three dimensional array of unknown size

>First, arrays are 0 based

Not always.

>2. Array can be only one type, you have 2 arrays As Single and 1 array As Long

Or we can declare as variant ...

> it looks like you need 2D array

yep, that looks to be the case

RE: VBA three dimensional array of unknown size

If the content of arrays with the same index is logically linked, it may be useful to build user defined type with required structure and have array with one dimension only.

combo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close