Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dsh dsh is offline
external usenet poster
 
Posts: 5
Default Dynamic multi-dimensional array


Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Dynamic multi-dimensional array

Dim Arr as variant
arr = array(5,6,10)



DSH wrote:

Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
dsh dsh is offline
external usenet poster
 
Posts: 5
Default Dynamic multi-dimensional array

I need to dynamically set the number of dimensions and elements, not the
values of the elements. The dimensions and elements are dynamic, i.e. they
change. So I need a way programmatically to easily change these. arr() may
be arr(5, 6, 10) or arr(1, 2, 9, 4), etc. etc.

"Dave Peterson" wrote:

Dim Arr as variant
arr = array(5,6,10)



DSH wrote:

Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.


--

Dave Peterson
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Dynamic multi-dimensional array

Is this what you are wanting? Hope this helps! If so, let me know, click
"YES" below.

dim arr()

dim s as string

s = "5, 6, 10"

arr = Split(s, ",")


--
Cheers,
Ryan


"DSH" wrote:

Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
dsh dsh is offline
external usenet poster
 
Posts: 5
Default Dynamic multi-dimensional array

No, sorry. I didn't state my original question well. I need an easy way to
change the number of dimensions of an array based on the changing value of
the number of dimensions and elements.

Here's the long way to do it:

numberOfdimensions = n

d(0) = 5
d(1) = 6
d(2) = 10

select case numberOfdimensions:

case 1:
redim arr(d(0))
case 2:
redim arr(d(0), d(1))
case 3:
redim arr(d(0), d(1), d(2))

etc. etc

end select

***

I'm looking for a simpler way. The following won't work, but is there a
similar way to do this:

for ddx = 0 to 2
s = s & d(ddx) & ", " ' s will end up = "5, 6, 10"
next ddx

redim arr(s)

Thanks again.

"Ryan H" wrote:

Is this what you are wanting? Hope this helps! If so, let me know, click
"YES" below.

dim arr()

dim s as string

s = "5, 6, 10"

arr = Split(s, ",")


--
Cheers,
Ryan


"DSH" wrote:

Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Dynamic multi-dimensional array

I think the only way you will be able to do what you want is this way...

Dim arr(), Temp() As String
Dim s As String
s = "5, 6, 10"
Temp = Split(s, ",")
Select Case UBound(Temp)
Case 0 ' One dimensional array
ReDim arr(Temp(0))
Case 1 ' Two dimensional array
ReDim arr(Temp(0), Temp(1))
Case 2 ' Three dimensional array
ReDim arr(Temp(0), Temp(1), Temp(2))
Case <<etc. ' Keep this structure going depending on the maximum needed
......
End Select

--
Rick (MVP - Excel)


"DSH" wrote in message
...
Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.


  #7   Report Post  
Posted to microsoft.public.excel.programming
dsh dsh is offline
external usenet poster
 
Posts: 5
Default Dynamic multi-dimensional array

Okay, I guess I will have to stick with the Select statement to do this.
Thanks.

"Rick Rothstein" wrote:

I think the only way you will be able to do what you want is this way...

Dim arr(), Temp() As String
Dim s As String
s = "5, 6, 10"
Temp = Split(s, ",")
Select Case UBound(Temp)
Case 0 ' One dimensional array
ReDim arr(Temp(0))
Case 1 ' Two dimensional array
ReDim arr(Temp(0), Temp(1))
Case 2 ' Three dimensional array
ReDim arr(Temp(0), Temp(1), Temp(2))
Case <<etc. ' Keep this structure going depending on the maximum needed
......
End Select

--
Rick (MVP - Excel)


"DSH" wrote in message
...
Is it possible to create a dynamic multi-dimensional array? I know the
following will not work, but something to the effect:

dim arr()

dim s as string

s = "5, 6, 10"

redim arr(s) 'i.e. redim arr(5, 6, 10)

Thanks.


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Dimensional Array steve Excel Programming 4 September 26th 06 07:33 PM
Multi Dimensional Array andym Excel Programming 11 July 10th 06 05:09 AM
Multi-Dimensional Array Let & Get Trip[_3_] Excel Programming 0 September 21st 05 08:41 PM
How to declare Multi-dimensional dynamic array? Terence Excel Programming 1 August 11th 03 04:55 AM
Declaring Dynamic Multi-dimensional Array JohnV[_2_] Excel Programming 2 July 15th 03 06:58 PM


All times are GMT +1. The time now is 02:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"