Page 105 - Open Soource Technologies 304.indd
P. 105
Unit 5: VB String and Operators
’ ShortenTextToChars
’ This function returns a shortened version of the InputText parameter that is
’ NumberOfCharacters in length. This function is primarily designed for use with
’ fully-qualified file names. With a file name, the function will remove or truncate
’ an element of the path (e.g., a folder name), replacing the removed text with the string
’ “...”. While this is intended for use with file names, it will work with any text string.
’ When used on text that does not contain ‘\’ characters, it typically just truncates the
’ right side of InputText.
’ Returns vbNullString is an error occurred.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Dim ResString As String
Dim Res As Long
Dim ErrorNumber As Long
Dim ErrorText As String
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Ensure that InputText is not an empty string
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
If InputText = vbNullString Then
MsgBox “The InputText parameter is an empty string”
ShortenTextToChars = vbNullString
Exit Function
End If
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Test for NumberOfCharacters <= 3. If the InputText
’ is 3 or fewer characters, PathCompactPathEx would replace the
’ entire string with “...”. We don’t want that. Return the entire
’ InputText.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
If Len(InputText) <= 3 Then
ShortenTextToChars = InputText
Exit0 Function
End If
’ Test for NumberOfCharacters less than equal to 3.
’ If the NumberOfCharacters <= 3, PathCompactPathEx would replace
’ the entire InputString with “...”.
’ Instead, return the left-most characters and get out.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
If NumberOfCharacters <= 3 Then
LOVELY PROFESSIONAL UNIVERSITY 99