Page 106 - Open Soource Technologies 304.indd
P. 106
Event Driven Programming
ShortenTextToChars = Left(InputText, NumberOfCharacters)
Exit Function
End If
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Ensure we have a valid number of characters. If NumberOfCharacters
’ is less than or equal to 0, or greater than the length of
’ the InputText, PathCompactPathEx will crash the application.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
If NumberOfCharacters <= 0 Then
MsgBox “The NumberOfCharacters must be greater than 0.”
ShortenTextToChars = vbNullString
Exit Function
End If
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Here we test if the length of InputTex is equal to
’ NumberOfCharacters. If they are equal, return the
’ the entire string and exit. If we allowed
’ PathCompactPathEx to process the string, it would truncate
’ on the right and replace the last three characters on the
’ right with “...”. We don’t want that behavior — we
’ want to return the entire string.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
If Len(InputText) = NumberOfCharacters Then
ShortenTextToChars = InputText
Exit Function
End If
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Initialize the buffer. When PathCompactPathEx
’ creates its string, it considers NumberOfCharacters
’ to include room for the trailing null character. Thus
’ the actual number of real characters it returns will be
’ NumberOfCharacters-1. Thus, we allocate the string
’ to NumberOfCharacters+2 = 1 because we want
’ NumberOfCharacters (without the trailing null)
’ returned, + 1 for trailing null.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
100 LOVELY PROFESSIONAL UNIVERSITY