LEN(string | varname) |
Returns the number of characters in a string (Long). |
string | The text string (String). |
varname | The name of the variable (String). |
REMARKS |
* When VBA stores a string in memory, it always stores the length of the string in a long integer at the start of the string. * This function retrieves this value and is therefore faster than having to examine the actual characters. * This function is useful for determining whether a string is a zero-length string ("") and should be used before comparing to a zero length string. * You must only enter one of the two arguments (either "string" or "varname"). * This function can also be used to determine the number of bytes used to store a variable. * If "varname" is Null, then Null is returned. * If "varname" is a Variant then it is treated the same as a string. * If "varname" is a user defined type, then the size returned is as it will be written to a file is returned. * You can use the LENB function to use with byte data. * The equivalent Excel function is LEN * The equivalent .NET function is Microsoft.VisualBasic.Strings.Len * For the Microsoft documentation refer to docs.microsoft.com |
Debug.Print Len("sometext") '= 8
Debug.Print Len("length of text") '= 14
Debug.Print Len("true") '= 4
Debug.Print Len(true) ' compile error
Debug.Print Len(100) ' compile error
Dim lResult As Long
lResult = Len("development")
Debug.Print lResult
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited Top