Looking for work? Check out our jobs area.
*/
*/

View \WORDWRAP.FRM

Carl Franklin's WordWrap Function

Submitted By: WEBMASTER
Rating: starstarstarstarstar (Rate It)


VERSION 2.00
Begin Form frmWrap
   Caption         =   "Carl Franklin's WordWrap Function"
   ClientHeight    =   2790
   ClientLeft      =   1095
   ClientTop       =   1485
   ClientWidth     =   7365
   Height          =   3195
   Left            =   1035
   LinkTopic       =   "Form1"
   ScaleHeight     =   2790
   ScaleWidth      =   7365
   Top             =   1140
   Width           =   7485
   Begin TextBox Text1
      Height          =   2460
      Left            =   135
      MultiLine       =   -1  'True
      TabIndex        =   1
      Top             =   150
      Width           =   4785
   End
   Begin CommandButton Command1
      Caption         =   "Save"
      Height          =   495
      Left            =   5175
      TabIndex        =   0
      Top             =   135
      Width           =   1215
   End
   Begin Label Label1
      Caption         =   "This function will save text in the textbox to a file called ""MYFILE.TXT"" in the directory that the program is being run from.  Probably VB in this case.  See the ""CMDIALOG"" sample code for use with printing."
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   1770
      Left            =   5130
      TabIndex        =   2
      Top             =   750
      Width           =   2145
      WordWrap        =   -1  'True
   End
End

Sub Command1_Click ()
'To use this function with a text box, make sure the
'text box's Multiline property to True, and use the
'following code:

    '-- VB functions that take strings as parameters
    'will not accept a Text property.
    T$ = Text1.Text
    '-- Get the formatted text (45 characters wide)
    Wrapped$ = WordWrap$(T$, 45)
    '-- Save the text to a file.
    Open "MYFILE.TXT" For Output As 1
    Print #1, Wrapped$
    Close #1

End Sub

Function WordWrap$ (St$, Length)


'-- This function converts raw text into CRLF delimited lines.

    Length = Length + 1
    St$ = Trim$(St$)
    Cr$ = Chr$(13)
    Crlf$ = Chr$(13) & Chr$(10)

    Do
        L = Len(NextLine$)
        S = InStr(St$, " ")
        C = InStr(St$, Cr$)

        If C Then
            If L + C <= Length Then
                Text$ = Text$ & NextLine$ & Left$(St$, C)
                NextLine$ = ""
                St$ = Mid$(St$, C + 1)
                GoTo LoopHere
            End If
        End If
        If S Then
            If L + S <= Length Then
                DoneOnce = True
                NextLine$ = NextLine$ & Left$(St$, S)
                St$ = Mid$(St$, S + 1)
            ElseIf S > Length Then
                Text$ = Text$ & Crlf$ & Left$(St$, Length)
                St$ = Mid$(St$, Length + 1)
            Else
                Text$ = Text$ & NextLine$ & Crlf$
                NextLine$ = ""
            End If
        Else
            If L Then
                If L + Len(St$) > Length Then
                    Text$ = Text$ & NextLine$ & Crlf$ & St$ & Crlf$
                Else
                    Text$ = Text$ & NextLine$ & St$ & Crlf$
                End If
            Else
                Text$ = Text$ & St$ & Crlf$
            End If
            Exit Do
        End If

LoopHere:

    Loop

    WordWrap$ = Text$

End Function

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings