VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



WordWrap in only 5 codelines

by Max Christian Pohle (9 Submissions)
Category: String Manipulation
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (12 Votes)

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 :-)

Rate WordWrap in only 5 codelines

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

Download this snippet    Add to My Saved Code

WordWrap in only 5 codelines Comments

No comments have been posted about WordWrap in only 5 codelines. Why not be the first to post a comment about WordWrap in only 5 codelines.

Post your comment

Subject:
Message:
0/1000 characters