[AccessD] Parsing text

Stuart McLachlan stuart at lexacorp.com.pg
Thu Sep 15 21:22:10 CDT 2005


On 15 Sep 2005 at 17:53, Francisco Tapia wrote:

> does anyone have a routine that will do the following:
> 
> SOME TEXT ENTERED HERE
> SOME MORE ENTERED HERE
> AGAIN
> 
> it'd prefer to have the code handle this on the ON CHANGE EVENT the idea is 
> to have the text break at the 25th character but if the break is in the 
> middle of the word, I will need the break to occur before the word so it 
> ends up on the next line as the sample above is shown... i'm posting here in 
> case someone has ran into this situation before...
> 

Heres a simple wordwrap function.
Note that it only wraps on spaces. If a "word" (which may be any string of 
characters not including a space) is longer that MaxChars, it will not be 
split.

Function WordWrap(InputString As String, MaxChars As Long) As String
    Dim lngPointer As Long
    Dim lngLoopCount As Long
    Dim lngLastPointer As Long
    Dim lngLastSpace As Long

    For lngLoopCount = 1 To Len(InputString)
        lngPointer = lngPointer + 1
        If Mid(InputString, lngLoopCount, 1) = " " Then
            lngLastSpace = lngLoopCount
            lngLastPointer = lngPointer
        End If
        If lngPointer > MaxChars And lngLastPointer <> 0 Then
            Mid(InputString, lngLastSpace, 1) = Chr$(10)
            lngPointer = MaxChars - lngLastPointer + 1
        End If
    Next
    WordWrap = Replace(InputString, Chr$(10), vbCrLf)
End Function



-- 
Stuart





More information about the AccessD mailing list