Page 103 - Open Soource Technologies 304.indd
P. 103
Unit 5: VB String and Operators
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ This enum is used by SizeString
’ to indicate whether the supplied text
’ appears on the left or right side of
’ result string.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Public Enum SizeStringSide
TextLeft = 1
TextRight = 2
End Enum
Public Function SizeString(Text As String, Length As Long, _
Optional ByVal TextSide As SizeStringSide = TextLeft, _
Optional PadChar As String = “ “) As String
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ SizeString
’ This procedure creates a string of a specified length. Text is the original string
’ to include, and Length is the length of the result string. TextSide indicates whether
’ Text should appear on the left (in which case the result is padded on the right with
’ PadChar) or on the right (in which case the string is padded on the left). When padding on
’ either the left or right, padding is done using the PadChar. character. If PadChar is omitted,
’ a space is used. If PadChar is longer than one character, the left-most character of PadChar
’ is used. If PadChar is an empty string, a space is used. If TextSide is neither
’TextLeft or TextRight, the procedure uses TextLeft.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Dim sPadChar As String
If Len(Text) >= Length Then
‘if the source string is longer than the specified length, return the
‘ Length left characters
SizeString = Left(Text, Length)
Exit Function
End If
If Len(PadChar) = 0 Then
‘ PadChar is an empty string. use a space.
sPadChar = “ “
Else
‘ use only the first character of PadChar
sPadChar = Left(PadChar, 1)
End If
If (TextSide <> TextLeft) And (TextSide <> TextRight) Then
LOVELY PROFESSIONAL UNIVERSITY 97