Return Value

With user-defined types and Object variables, the Len function returns the size as it will be written to the file by the FilePut function. If an Object contains a String, it will return the length of the string. If an Object contains any other type, it will return the size of the object as it will be written to the file by the FilePut function.

The VBFixedString attribute can be applied to string fields in objects to indicate the size of the string, in bytes, when written to disk. The Len function uses the VBFixedString attribute, if available, when determining the size of Object variables.

Note

The Len function may not be able to determine the actual number of storage bytes required when used with variable-length strings in user-defined data types.

Note

The LenB function in earlier versions of Visual Basic returns the number of bytes in a string rather than characters. It is used primarily for converting strings in double-byte character set (DBCS) applications. All current Visual Basic strings are in Unicode, and LenB is no longer supported.

The Len function accepts only String and Object variables as parameters. If an Object contains a String, it will return the length of the String. If a parameter is a NULL Object reference, the function returns zero. If an Object contains any other type, an exception is thrown.