Subscribe:Posts Comments

You Are Here: Home � � Word Wrap

Using Visual Basic to word wrap :

Function WordWrap$ (St$, Length)

'-- This function converts raw text into CRLF delimited lines.
Length = Length + 1
St$ = Trim$(St$)
Cr$ = Chr$(13)
Crlf$ = Chr$(13) & Chr$(10)
Do
L = Len(NextLine$)
S = InStr(St$, " ")
C = InStr(St$, Cr$)
If C Then
If L + C <= Length Then
Text$ = Text$ & NextLine$ & Left$(St$, C)
NextLine$ = ""
St$ = Mid$(St$, C + 1)
GoTo LoopHere
End If
End If
If S Then
If L + S <= Length Then
DoneOnce = True
NextLine$ = NextLine$ & Left$(St$, S)
St$ = Mid$(St$, S + 1)
ElseIf S > Length Then
Text$ = Text$ & Crlf$ & Left$(St$, Length)
St$ = Mid$(St$, Length + 1)
Else
Text$ = Text$ & NextLine$ & Crlf$
NextLine$ = ""
End If
Else
If L Then
If L + Len(St$) > Length Then
Text$ = Text$ & NextLine$ & Crlf$ & St$ & Crlf$
Else
Text$ = Text$ & NextLine$ & St$ & Crlf$
End If
Else
Text$ = Text$ & St$ & Crlf$
End If
Exit Do
End If

LoopHere:

Loop
WordWrap$ = Text$

End Function
Tags:

0 comments

Leave a Reply