ChiefRedBull
09-08-2002, 08:07 AM
This just came up in General, and I figured it's a handy function to have lying around... :)
Private Function WrapText$(ByVal sText As String, ByVal lLineLength As Long)
Dim i As Long, j As Long
Dim ShortString As String
Dim PrintString As String
' setup the vars
i = 1
j = 1
Do
' grab the next line length from
' the long string
ShortString = Mid$(sText, i, lLineLength)
' locate the nearest word break character
' from the end of the line
j = InStrRev(ShortString, " ")
' if there is a word break, then we should
' cut off the line at that break, otherwise,
' the entire line is used
If j <> 0 Then ShortString = Mid$(ShortString, 1, j)
' now add this trimmed line to the
' wrapped printer string
PrintString = PrintString & ShortString & vbCrLf
' finally move the pointers on a bit
' so that we get the next line length
If j = 0 Then j = lLineLength
i = i + j
' exit the loop if we've hit the end
' of the long string passed in
If i > Len(sText) Then Exit Do
Loop
' return the results
WrapText = PrintString
End Function
Bugs via PM please :p
Private Function WrapText$(ByVal sText As String, ByVal lLineLength As Long)
Dim i As Long, j As Long
Dim ShortString As String
Dim PrintString As String
' setup the vars
i = 1
j = 1
Do
' grab the next line length from
' the long string
ShortString = Mid$(sText, i, lLineLength)
' locate the nearest word break character
' from the end of the line
j = InStrRev(ShortString, " ")
' if there is a word break, then we should
' cut off the line at that break, otherwise,
' the entire line is used
If j <> 0 Then ShortString = Mid$(ShortString, 1, j)
' now add this trimmed line to the
' wrapped printer string
PrintString = PrintString & ShortString & vbCrLf
' finally move the pointers on a bit
' so that we get the next line length
If j = 0 Then j = lLineLength
i = i + j
' exit the loop if we've hit the end
' of the long string passed in
If i > Len(sText) Then Exit Do
Loop
' return the results
WrapText = PrintString
End Function
Bugs via PM please :p