Results 1 to 5 of 5

Thread: Replacing Multiple vbNewlines

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    31

    Replacing Multiple vbNewlines

    Hi, i'm trying to replace multiple vbnewline's as to only allow two vbnewline's in my textbox. I sort of have a idea how i could do it by counting each instance of vbnewline that appears in my string and then replacing them with only two vbnewline's. But the problem is how could i duplicate the vbnewline sub string using a integer value to match the number of instances found in the string, something simmilar to the string() function.
    Last edited by Jackkkkk; Oct 17th, 2010 at 02:18 AM.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Replacing Multiple vbNewlines

    I'm struggling to work out what the data in your TextBox might look like, can you give and example of 'before'and 'after' please ?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Replacing Multiple vbNewlines

    text1.text = replace(text.text, vblf & vbcr, "")
    will remove all empty lines in text box, except if there is empty line at the end
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    31

    Re: Replacing Multiple vbNewlines

    @Doogle The correct formatting of the data would look like this:

    Code:
    Description:
    
    Description here
    more info
    more info
    
    even more info

    Incorrect would be something like this:

    Code:
    Description:
    
    
    
    Description here
    more info
    more info
    
    
    even more info
    So basically i need to replace any new lines that are more than 2, with 2 new lines.
    Last edited by Jackkkkk; Oct 17th, 2010 at 03:19 AM.

  5. #5
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Replacing Multiple vbNewlines

    Keep looping until all triple vbNewLines are replaced with two vbNewLines.

    vb Code:
    1. Do While InStr(Text1.Text, vbNewLine & vbNewLine & vbNewLine) > 0
    2.     Text1.Text = Replace(Text1.Text, vbNewLine & vbNewLine & vbNewLine, vbNewLine & vbNewLine)
    3. Loop
    Last edited by Chris001; Oct 17th, 2010 at 09:04 AM. Reason: typo

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