In my code I'm using the len() function to get the length of the data content assigned to a variable. And here I found some strange behavior - but see my code first and then my annotations / questions.
Dim Array(1 To 3) As Integer
' some code
Array(1)=345
' some code
If len(Array(1)) = 3 Then
' do this (here is the expected code bunch)
Else
' do this (and here the unexpected code bunch)
End If
Google guided me to MS len()-function and here I read the first sentence with an "or" and (for me) no further explanation, which is a little confusing to me...
(Len function) Returns a Long containing the number of characters in a string or the number of bytes required to store a variable.
On a second Google recommended site I found the very helpful hint that
- VBA Len Function can count the number of characters in variables declared as strings or variants
- If VBA Len is used with an integer, long, single or double then VBA Len is going to count the number of bytes needed to store the variable
Okay, but how can I get the length of the data content if the variable is Integer - like in my code snippet?
Here I found in these links (Link_1,
Link_2)
the suggestion of conversion by using TEXT()
and CStr()
- the second link recommends CStr()
because of some drawbacks of TEXT()
.
Now my Question(s):
Is it a proper way to use
CStr()
to solve my issue?And on the other hand an additional question arises because of my research: How can I get the amount of used bytes from variables declared as strings or variants?
Thanks a lot for your help in advance!