To find the length of a string you should use the Len function.
The Len function includes spaces and other symbols.
Example VB code – display the length of user input
show
Dim userInput As String = ""
userInput = InputBox("Please enter your name")
MsgBox ("Your name is " & Len(userInput) & " characters long.")
Example VB code – length validation
show
Dim newUsername As String = ""
Do
newUsername = InputBox ("Please enter your new username")
If Len(newUsername)<5 Then
MsgBox ("Your new username must be at least 5 characters long. Please re-enter.")
End If
Loop Until Len(newUsername)>=5
MsgBox ("Your new username has been set to " & newUsername)