Dynamic Arrays

T

triaz

Hi,

The data I want to populate an array with is of variable size ie it is
dynamic could be 4, 10 or 200 items. How do I create an array that will
handle this/

Regards

T.
 
H

Helmut Weber

Hi triaz,

see help on:
redim
redim preserve
Presumably slow.

Or count your items beforehand.

Or use a collection, like this:

Sub Test345x()
Dim l As Long ' just a counter
Dim x As Long ' a random number in the range from 1 to 100
Dim oCll As Collection
Set oCll = New Collection
Randomize
x = Int((100) * Rnd + 1)
For l = 1 To x
oCll.Add Format(l, "000")
Next
MsgBox oCll(Int((x) * Rnd + 1)) ' an item from the collection
MsgBox oCll.Count ' the number of items in the collection
End Sub

see help on "randomize" and "rnd" in addition.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

I messed up longs and integers.
No good style, but not relevant here.

Sorry.

Helmut Weber
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top