Can you dimension an array in a way other than Variant?

E

ExcelMonkey

I am loading text into a large array dimensioned as a Variant. Is this the
only way to dimension the Array? I am wondering if I can dimension the array
in a less memory intensive manor?

Thanks

EM
 
P

Per Jessen

I am loading text into a large array dimensioned as a Variant.  Is this the
only way to dimension the Array?  I am wondering if I can dimension the array
in a less memory intensive manor?

Thanks

EM

Hi

Yes you can use the same types as with other variables.

Dim MyArray(10) as String

Regards,
Per
 
J

Jim Thomlinson

While you are correct that you can declare your array as any data type you
want, your resulting array will use the same amount of memory as a variant.
The only difference is that the explicitly declared array will be more
efficient since the variable type will not need to be determined at run time.

In short whether it is an array of strings or a variant it is going to hold
the exact same data (an array of strings).
 
P

Peter T

Hi Jim, not sure that's quite right

Sub foo()
Dim sArr(1 To 2) As String
Dim vArr(1 To 2) As Variant

Debug.Print VarPtr(sArr(2)) - VarPtr(sArr(1)) ' 4
Debug.Print VarPtr(vArr(2)) - VarPtr(vArr(1)) ' 16

End Sub

Regards,
Peter T
 

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