Page 102 - Open Soource Technologies 304.indd
P. 102
Event Driven Programming
‘ put some arbitrary values in FS And S.
’ This is for demonstration purposes only.
’ It is not required for the code to work.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
FS = “ABC” ‘ length of FS is still 10 chars, even though it contains only 3 chars.
S = “DEF” ‘ length of S is 3 chars.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ test whether FS is fixed length string
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
OrigLen = Len(FS) ‘ length of FS string
OrigVal = FS ‘ save original value of FS
FS = FS & “ “ ‘ attempt to append a space to the end of FS
If OrigLen = Len(FS) Then ‘ if the length of FS didn’t change, the string is fixed length
Debug.Print “FS is a fixed length string”
Else ‘ if the length of FS did change, the string is sizable
Debug.Print “FS is a sizable string”
‘restore original value
FS = OrigVal
End If
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ test whether S is fixed length string
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
OrigLen = Len(S) ‘ save length of S
OrigVal = S ‘ save original value
S = S & “ “ ‘ attempt to append a space to the end of S
If OrigLen = Len(S) Then ‘ if length of S didn’t change, the string if fixed lengh
Debug.Print “S is a fixed length string”
Else’ if the length of S did change, the string is sizable
Debug.Print “S is a sizable string”
‘restore original value
S = OrigVal
End If
The output in the Immediate Window in VBA of the code above is:
FS is a fixed length string
S is a sizable string
5.1.5 SizeString
The following VBA procedure will return a string variable containing the specified text, on either
the left of the right, padded with PadChar on either the right or left to make a string Length
characters long.
96 LOVELY PROFESSIONAL UNIVERSITY