View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Assign Values to array

Dim V as variant
declares V as a variant that will end up holding an array.

This is different than this:
Dim V() As Variant
Which declares V as an array that will hold different types of elements.


"Rick Rothstein (MVP - VB)" wrote:

The Array function requires it. That is because you can put almost anything
in the argument list to the Array function, as long as you remember what is
what, of course.<g For example...

Dim V As Variant
V = Array(123, "Text String", Range("A1"))
MsgBox V(0) & vbCrLf & V(1) & vbCrLf & V(2).Address

Notice that the 3rd element, V(2), is a Range object, so to MessageBox out
something from it, you need to reference one of its properties. True, I
could have let it use its default Value property, but I wanted to positively
demonstrate that it was an actual object being stored in the third element.

Rick

"Jeff" wrote in message
...

That works thanks for your help.

Is there a reason it has to be declared as a variant, I guess it really
doesnt matter for my case.


"Dave Peterson" wrote:

One way:

dim kk() as variant
dim iCtr as long
kk = array(1,2,3,4,5,6,7,8,9,0)

for ictr = lbound(kk) to ubound(kk)
msgbox kk(ictr) & "--" & ictr
next ictr



Jeff wrote:

Hi,

I wanted to assign constants to an array at once.

Dim KK(1 to 10) as double

KK = ( 1, 2, 3, 4, 5, 6, 7,8,9,0)
Doesnt work...

How can I assign values to the array at once without assigning one by
one.
KK(1) = 1
KK(2) = 2
... etc

Thanks

--

Dave Peterson


--

Dave Peterson