Hi,
How do you get/return the size of a variable or object in
bytes.
Code:example :
Public Sub Test
Dim Name as String
Dim Value as Long
Name = "John Black"
Value = SizeOf(Name)
End Sub
Printable View
Hi,
How do you get/return the size of a variable or object in
bytes.
Code:example :
Public Sub Test
Dim Name as String
Dim Value as Long
Name = "John Black"
Value = SizeOf(Name)
End Sub
see help on LEN keyword
It's actually the Len function, not keyword :rolleyes:.
It is used like this:
Code:Dim Name As String
Dim Value As Long
Name = "John Black"
Value = Len(Name)
Debug.Print Value
Will this work for Integers and Array?
Here is Data Type Summary from MSDN:
Code:Byte 1 byte
Boolean 2 bytes
Integer 2 bytes
Long 4 bytes
Single 4 bytes
Double 8 bytes
Currency 8 bytes
Decimal 14 bytes
Date 8 bytes
Object 4 bytes (Any Object reference)
String (variable-length) 10 bytes + string length 0 to approximately 2 billion
String (fixed-length) Length of string 1 to approximately 65,400
Variant (with numbers) 16 bytes Any numeric value up to the range of a Double
Variant (with characters) 22 bytes + string length Same range as for variable-length String
User-defined (using Type) Number required by elements The range of each element is the same as the range of its data type.
Arrays of any data type require 20 bytes of memory plus 4 bytes for each array dimension plus the number of bytes occupied by the data itself. The memory occupied by the data can be calculated by multiplying the number of data elements by the size of each element. For example, the data in a single-dimension array consisting of 4 Integer data elements of 2 bytes each occupies 8 bytes. The 8 bytes required for the data plus the 24 bytes of overhead brings the total memory requirement for the array to 32 bytes.
A Variant containing an array requires 12 bytes more than the array alone.
LenB will return the exact size in bytes for UDT's and Variants.