The Len() function returns the length of a string. After the following statements execute:

Name = InputBox("Enter your first name") NameLen = Len(Name)

the variable NameLen contains the length of the string entered by the user in the input box.

The Len() function is frequently used as a first test for invalid input, as in the following lines:

MsgBox ("NAME field can't be empty") Else

MsgBox ("Thank you for registering with us") EndIf

The Len() function can accept any base type as argument, and it returns the number of bytes required to store the variable. The expression


will return 8 (by default, floating-point values are stored in Double variables). The expression Len(12)

will return 4, because integers are stored in 4 bytes.

0 0

Post a comment