#1   Report Post  
Posted to microsoft.public.excel.programming
Ten Ten is offline
external usenet poster
 
Posts: 9
Default Array size

Could anyone please advice me with some Array-help (or
where to find the information):

I need to have an array

I got this far...
Dim tempArray
tempArray = Array() '(or tempArray = Array("")
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

And it crash on the tempArray(0) - or on tempArray(1) if I
use tempArray = Array("") - because it's not defined.
However, I don't want to specify the length of my Array,
but have it dynamic. How can I achieve this?

Thx!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array size

Sub tester3()
Dim tempArray(0 To 10)
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

MsgBox "TempArray, 0 = " & tempArray(0) & _
vbNewLine & "TempArray, 1 = " & tempArray(1)

End Sub



--
Regards,
Tom Ogilvy


"ten" wrote in message
...
Could anyone please advice me with some Array-help (or
where to find the information):

I need to have an array

I got this far...
Dim tempArray
tempArray = Array() '(or tempArray = Array("")
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

And it crash on the tempArray(0) - or on tempArray(1) if I
use tempArray = Array("") - because it's not defined.
However, I don't want to specify the length of my Array,
but have it dynamic. How can I achieve this?

Thx!



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ten Ten is offline
external usenet poster
 
Posts: 9
Default Array size

Thx
However, I still need to have more dynamically size on
this.
I am doing a loop through a lot of data, and sometime sI
need an array of only 1, sometimes I need 100. I guess
that for time concideration to build an array with size
100 (which I use only a few times, and even not at all)
would take a lot of memory.
Are there really no way of dynamically changing the Array
size during the program in VBA?

Correct me if I am wrong. And/or please add more solutions
if you have.

-----Original Message-----
Sub tester3()
Dim tempArray(0 To 10)
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

MsgBox "TempArray, 0 = " & tempArray(0) & _
vbNewLine & "TempArray, 1 = " & tempArray(1)

End Sub



--
Regards,
Tom Ogilvy


"ten" wrote in message
...
Could anyone please advice me with some Array-help (or
where to find the information):

I need to have an array

I got this far...
Dim tempArray
tempArray = Array() '(or tempArray = Array("")
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

And it crash on the tempArray(0) - or on tempArray(1)

if I
use tempArray = Array("") - because it's not defined.
However, I don't want to specify the length of my Array,
but have it dynamic. How can I achieve this?

Thx!



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Array size

copied & pasted from the VBA help manual

Declaring a Dynamic Array
By declaring a dynamic array, you can size the array while the code is
running. Use a Static, Dim, Private, or Public statement to declare an
array, leaving the parentheses empty, as shown in the following example.

Dim sngArray() As Single
Note You can use the ReDim statement to declare an array implicitly within
a procedure. Be careful not to misspell the name of the array when you use
the ReDim statement. Even if the Option Explicit statement is included in
the module, a second array will be created.

In a procedure within the array's scope, use the ReDim statement to change
the number of dimensions, to define the number of elements, and to define
the upper and lower bounds for each dimension. You can use the ReDim
statement to change the dynamic array as often as necessary. However, each
time you do this, the existing values in the array are lost. Use ReDim
Preserve to expand an array while preserving existing values in the array.
For example, the following statement enlarges the array varArray by 10
elements without losing the current values of the original elements.

ReDim Preserve varArray(UBound(varArray) + 10)
Note When you use the Preserve keyword with a dynamic array, you can
change only the upper bound of the last dimension, but you can't change the
number of dimensions.





"ten" wrote in message
...
Thx
However, I still need to have more dynamically size on
this.
I am doing a loop through a lot of data, and sometime sI
need an array of only 1, sometimes I need 100. I guess
that for time concideration to build an array with size
100 (which I use only a few times, and even not at all)
would take a lot of memory.
Are there really no way of dynamically changing the Array
size during the program in VBA?

Correct me if I am wrong. And/or please add more solutions
if you have.

-----Original Message-----
Sub tester3()
Dim tempArray(0 To 10)
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

MsgBox "TempArray, 0 = " & tempArray(0) & _
vbNewLine & "TempArray, 1 = " & tempArray(1)

End Sub



--
Regards,
Tom Ogilvy


"ten" wrote in message
...
Could anyone please advice me with some Array-help (or
where to find the information):

I need to have an array

I got this far...
Dim tempArray
tempArray = Array() '(or tempArray = Array("")
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

And it crash on the tempArray(0) - or on tempArray(1)

if I
use tempArray = Array("") - because it's not defined.
However, I don't want to specify the length of my Array,
but have it dynamic. How can I achieve this?

Thx!



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array size

dim temparray()
redim temparray(1 to 5)

for i = 1 to 5
temparray(1) = i^2
Next
redim preserve temparray(1 to 15)
for i = 6 to 15
temparray = i^0.5
next


--
Regards,
Tom Ogilvy


"ten" wrote in message
...
Thx
However, I still need to have more dynamically size on
this.
I am doing a loop through a lot of data, and sometime sI
need an array of only 1, sometimes I need 100. I guess
that for time concideration to build an array with size
100 (which I use only a few times, and even not at all)
would take a lot of memory.
Are there really no way of dynamically changing the Array
size during the program in VBA?

Correct me if I am wrong. And/or please add more solutions
if you have.

-----Original Message-----
Sub tester3()
Dim tempArray(0 To 10)
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

MsgBox "TempArray, 0 = " & tempArray(0) & _
vbNewLine & "TempArray, 1 = " & tempArray(1)

End Sub



--
Regards,
Tom Ogilvy


"ten" wrote in message
...
Could anyone please advice me with some Array-help (or
where to find the information):

I need to have an array

I got this far...
Dim tempArray
tempArray = Array() '(or tempArray = Array("")
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

And it crash on the tempArray(0) - or on tempArray(1)

if I
use tempArray = Array("") - because it's not defined.
However, I don't want to specify the length of my Array,
but have it dynamic. How can I achieve this?

Thx!



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Array size

In order to have it dynamic

Dim tempArray()
Redim tempArray(0 to 1)

Alan Beban

ten wrote:
Could anyone please advice me with some Array-help (or
where to find the information):

I need to have an array

I got this far...
Dim tempArray
tempArray = Array() '(or tempArray = Array("")
tempArray(0) = "someValue"
tempArray(1) = "someOtherValue"

And it crash on the tempArray(0) - or on tempArray(1) if I
use tempArray = Array("") - because it's not defined.
However, I don't want to specify the length of my Array,
but have it dynamic. How can I achieve this?

Thx!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Array size


"ten" wrote in message
...
Thx
However, I still need to have more dynamically size on
this.
I am doing a loop through a lot of data, and sometime sI
need an array of only 1, sometimes I need 100. I guess
that for time concideration to build an array with size
100 (which I use only a few times, and even not at all)
would take a lot of memory.
Are there really no way of dynamically changing the Array
size during the program in VBA?

Correct me if I am wrong. And/or please add more solutions
if you have.


There is, you can used Redim Preserve BUT be aware there's an
overhead.

Each time you do this the system has to effectively make a new
copy of the array and throw away the old one. With a small array,
and 100 subscripts IS small I'd suggest you initially dimension
it to 100 and then redim it at the end of the iteration

Keith


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
Worksheet Function to Create Array of Size n with values x Through Dial222 Excel Discussion (Misc queries) 1 December 6th 07 11:21 AM
Is there an array size limit for MMULT or MINVERSE in excel 2007? jimr315 Excel Worksheet Functions 4 February 7th 07 10:48 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
Can we write VBA code to set all column/row's size back to default size? Charles Williams Excel Programming 0 July 8th 03 03:56 PM
Can we write VBA code to set all column/row's size back to default size? Earle Excel Programming 0 July 8th 03 02:46 PM


All times are GMT +1. The time now is 10:29 PM.

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

About Us

"It's about Microsoft Excel"