Results 1 to 4 of 4

Thread: [RESOLVED] How To Remove Extra Lines From Textbox Or RichTextBox

  1. #1

    Thread Starter
    Addicted Member _RaJ_'s Avatar
    Join Date
    Apr 2008
    Location
    India!
    Posts
    198

    Resolved [RESOLVED] How To Remove Extra Lines From Textbox Or RichTextBox

    How To Remove Extra Lines From Textbox Or RichTextBox?

    my TXTBOX look's like
    ----------------------------------------
    NAME


















    NAME
    --------------------------------------


    How can i make it look like

    ------------------
    NAME

    NAME
    ------------------


    i am pissed @ this plz help !!

    ●════════════════════════════◄►═════════════════════════●
    ___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
    ●════════════════════════════◄►═════════════════════════●
    гαj

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: How To Remove Extra Lines From Textbox Or RichTextBox

    Code:
    Dim n As Long
    Dim arr() As String
    
    arr() = Split(Text1.Text, vbCrLf)
    Text1.Text = vbNullString
    
    For n = LBound(arr) To UBound(arr)
      If arr(n) <> vbNullString Then
        If Text1.Text <> vbNullString Then Text1.Text = Text1.Text & vbCrLf
        
        Text1.Text = Text1.Text & arr(n)
      End If
    Next n

  3. #3
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How To Remove Extra Lines From Textbox Or RichTextBox

    This seems to work fine, irrespective of how many extra blank lines you have in the multi-line text box:

    Code:
    Private Sub Command1_Click()
    While InStr(Text1.Text, vbCrLf & vbCrLf)
        Text1.Text = Replace(Text1.Text, vbCrLf & vbCrLf, vbCrLf)
    Wend
    End Sub
    
    Private Sub Form_Load()
    'Sample data with four extra blank lines
    Text1.Text = "Name" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "Name"
    End Sub
    Doctor Ed

  4. #4

    Thread Starter
    Addicted Member _RaJ_'s Avatar
    Join Date
    Apr 2008
    Location
    India!
    Posts
    198

    Re: How To Remove Extra Lines From Textbox Or RichTextBox

    wow doc....... that was brilliant......

    wish i can think like u

    ●════════════════════════════◄►═════════════════════════●
    ___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
    ●════════════════════════════◄►═════════════════════════●
    гαj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width