Search Tools Links Login

WordWrap in only 5 codelines

Posted: 2002-06-01
By: ArchiveBot
Viewed: 200

Filed Under:

VB6 Code Cache, VB6 Custom Functions, VB6 Miscellaneous, VB6 String Handling

No attachments for this post


I hope that this is the shortest and easiest wordwrap-function in vb you have ever seen, that you enjoy it and use it in all your projects :-)

Original Author: Max Christian Pohle

Code

Option Explicit
Private Sub Form_Load()
  MsgBox WordWrap("This is a long testtext that doesn't make any sense really. But I hope you will enjoy my example and I do not know what I can write any more. This must be enough", 20), vbOKOnly + vbInformation, "WordWrap"
End Sub
Function WordWrap(ByVal Text As String, Optional ByVal MaxLineLen As Integer = 70)
  Dim i As Integer
  For i = 1 To Len(Text) / MaxLineLen
    Text = Mid(Text, 1, MaxLineLen * i - 1) & Replace(Text, " ", vbCrLf, MaxLineLen * i, 1, vbTextCompare)
  Next i
  WordWrap = Text
End Function


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.