VBA/Excel/Access/Word/String Functions/len
Finding a string length
<source lang="vb">
Sub GetLength()
Dim MyString As String Dim StringLength As Integer MyString = "Hello World" StringLength = Len(MyString) MsgBox StringLength
End Sub
</source>
Get the length of a String
<source lang="vb">
Sub GetLengthOfString()
Dim stFullName As String stFullName = "C:\asdf\asdf.xls" MsgBox Len(stFullName)
End Sub
</source>
Using Len(string) to Check the Length of a String
<source lang="vb">
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
</source>