Hi all,
I need to know what is the default space occupied by a variant variable and its size?
And waht will be its space and size when u assign some value to the variant variable.
Printable View
Hi all,
I need to know what is the default space occupied by a variant variable and its size?
And waht will be its space and size when u assign some value to the variant variable.
Hi,
A variant with a numeric value takes 16 bytes, with a string, takes 22 bytes + string lenght.
Steph
You can use the Len function to retrieve this information..
Code:
Private Sub Form_Load()
Dim v As Variant
Debug.Print Len(v) ' returns 0
v = 15
Debug.Print Len(v) ' returns 2 (integer)
v = "JON"
Debug.Print Len(v) ' returns 3
End Sub
Better yet use the LenB function....
and I think steph meant that an integer value is 16 bits and 2 bytes.Code:Private Sub Form_Load()
Dim v As Variant
Debug.Print LenB(v)
v = 15
Debug.Print LenB(v)
v = "JON"
Debug.Print LenB(v)
End Sub
No, a variant is always that fat 16 byte, 128 bit, and for strings 22 bytes + string length * 2 bytes
WOW! That SUCKS!!
So then the best advice would be to not use Variants?
>So then the best advice would be to not use Variants?
Yeah, if you know what type of data you`ll be dealing with, then using the appropriate type is faster and smaller.