Computing.Net > Forums > Programming > vb6: insert vbcrlf after # of chars

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

vb6: insert vbcrlf after # of chars

Reply to Message Icon

Original Message
Name: Race
Date: August 2, 2003 at 19:01:13 Pacific
Subject: vb6: insert vbcrlf after # of chars
OS: XP Sp1
CPU/Ram: Athlon XP 2400, 256 MB
Comment:

What I want to do is take a string that is made up of words (sentences) and insert line breaks after a number of characters is reached, without breaking up any whole word of course. So if the line exceed the maximun number of characters per line, go back to the last word that fits under the limit and insert a vbCrlf, then continue on until all lines fit. I hope that makes sense.

If anyone has any example code or could point me in the right direction I would greatly appreciate it. Thanks.


Report Offensive Message For Removal


Response Number 1
Name: Chi Happens
Date: August 2, 2003 at 21:42:02 Pacific
Reply: (edit)

Here is a function:

Public Function BreakUpLines(ByVal DataIN As String, 
Optional ByVal LineCharLimit As Long = 80) As String
    Dim p As Long
    Dim DataOUT As String
    DataOUT = ""
    Do While Len(DataIN) > 0
        p = LineCharLimit
        If Len(DataIN) > p Then
            Do While Mid(DataIN, p, 1) <> " "
                p = p - 1
            Loop
            DataOUT = DataOUT & Left(DataIN, p) & vbCrLf
            DataIN = Mid(DataIN, p + 1, Len(DataIN))
        Else
            DataOUT = DataOUT & DataIN
            DataIN = ""
        End If
    Loop
    BreakUpLines = DataOUT
End Function


Report Offensive Follow Up For Removal

Response Number 2
Name: Race
Date: August 3, 2003 at 00:02:02 Pacific
Reply: (edit)

Thanks, it works perfectly. Chi Happens, Im a complete newbie to any kind of programming, if you have a free minute sometime could you add some comments about the above code to help me understand how the above function works.

Thanks again.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software