Using Len(string) to Check the Length of a String : len « String Functions « VBA / Excel / Access / Word






Using Len(string) to Check the Length of a String

 
Sub CheckPassword()
    Dim strPassword As String

BadPassword:
    strPassword = "pass"
    If Len(strPassword) = 0 Then
        End
    ElseIf Len(strPassword) < 6 Then
        MsgBox "less than 6.",vbOKOnly + vbCritical, "Unsuitable Password"
        GoTo BadPassword
    ElseIf Len(strPassword) > 15 Then
        MsgBox "too long." , vbOKOnly + vbCritical, "Unsuitable Password"
        GoTo BadPassword
    End If
End Sub
 

 








Related examples in the same category

1.Finding a string length
2.Get the length of a String