Syntax |
Len(expression) |
|
Description |
Returns the number of characters in expression or the number of bytes required to store the specified variable. |
|
Comments |
If expression evaluates to a string, then Len returns the number of characters in a given string or 0 if the string is empty. When used with a Variant variable, the length of the variant when converted to a String is returned. If expression is a Null, then Len returns a Null variant. If used with a non-String or non-Variant variable, the function returns the number of bytes occupied by that data element. When used with user-defined data types, the function returns the combined size of each member within the structure. Since variable-length strings are stored elsewhere, the size of each variable-length string within a structure is 2 bytes. The following table describes the sizes of the individual data elements: |
|
|
Data Element |
Size |
|
Integer |
2 bytes |
|
Long |
4 bytes |
|
Float |
4 bytes |
|
Double |
8 bytes. |
|
Currency |
8 bytes |
|
String |
Number of characters in the string. |
|
String |
The length of the string as it appears in the string's declaration. |
|
Objects |
0 bytes. Both data object variables and variables of type Object are always returned as 0 size. |
|
User-defined type |
Combined size of each structure member. Variable-length strings within structures require 2 bytes of storage. Arrays within structures are fixed in their dimensions. The elements for fixed arrays are stored within the structure and therefore require the number of bytes for each array element multiplied by the size of each array dimension: element_size * dimension1 * dimension2... |
|
The Len function always returns 0 with object variables or any data object variable. |
|
Example |
Const crlf = Chr$(13) + Chr$(10) Sub Main() |
|
|
'This example returns a table of lengths for standard numeric types. Dim lns(4) |
|
See Also |
InStr (function) |
L |