EmersonH.Com

Transforming Knowledge into Power

  • Increase font size
  • Default font size
  • Decrease font size
Home VB 6 String Word Wrap

Word Wrap

E-mail Print

Function WWrap(StrDummy As String, StrSize As Integer) As String

If Len(Trim(StrDummy)) < StrSize Then
WWrap = StrDummy
Exit Function
End If

Dim StrLine1 As String
Dim LoopI As Integer
Dim IntJ As Integer
LoopI = 1
StrLine1 = Mid(StrDummy, LoopI, StrSize)
WWrap = ""
While Trim(StrLine1) <> ""
If (Mid(StrDummy, (LoopI - 1) * Len(StrLine1) + 1, 1) <> " ") Then
IntJ = InStrRev(StrLine1, " ")
If IntJ <> 0 Then
StrDummy = Mid(StrDummy, 1, (LoopI - 1) * StrSize + IntJ - 1) + String(StrSize - IntJ + 1, " ") + Mid(StrDummy, (LoopI - 1) * StrSize + IntJ + 1)
End If
End If
LoopI = LoopI + 1
StrLine1 = Padr(Mid(StrDummy, (LoopI - 1) * StrSize + 1, StrSize), StrSize)
Wend
WWrap = StrDummy
End Function