Description
Returns the number of characters in a string or the number of bytes required to store a variable.
Syntax
Len(string | varname)
The Len function syntax has these parts:
Part |
Description |
string |
Any valid string expression. If string contains no valid data, Null is returned. |
varname |
Any valid variable name. If varname contains no valid data, Null is returned. |
Remarks
Caution
Len may not be able to determine the actual number of storage bytes required when used with user-defined data types.
Note
Another function (LenB) is provided for use with the double-byte character sets (DBCS) used in some Asian locales. Instead of returning the number of characters in a string, LenB returns the number of bytes used to represent that string. In areas where DBCS is not used, LenB behaves the same as Len.
See Also
InStr Function.
Example
This example uses the Len function to return the number of characters in a string or the number of bytes required to store a variable.
Type CustomerRecord ' Define user-defined type. ID As Integer Name As String * 10 Address As String * 30 End Type Dim Customer As CustomerRecord ' Declare variables. Dim MyInt As Integer, MyCur As Currency MyString = "Hello World" ' Initialize. MyLen = Len(MyInt) ' Returns 2. MyLen = Len(Customer) ' Returns 42. MyLen = Len(MyString) ' Returns 11. MyLen = Len(MyCur) ' Returns 8.