new line in rich text box-VBForums
Results 1 to 11 of 11

Thread: new line in rich text box

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    2

    new line in rich text box

    Guyz,
    i got a problem here,
    actually, it is pretty simple.
    i want to insert a new line in richtextbox by using the VB programming code.

    for example,
    i have richtextbox1 and command1,
    and i make this code :

    private_sub command1_click

    richtextbox1.text = "abcdefghijk" & "lmnopqrstu"

    end sub

    the result when command1 is clicked :

    abcdefhijklmnopqrstu

    what i want is to put the "lmnopqrstu" on the next line, like this :

    abcdefghijk
    lmnopqrstu

    can anyone help ?

    i know it is pretty simple, but i need the answer,
    please reply...

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    2

    VB version

    one more thing,

    im using Visual Basic 6.0.

    Thanks !

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,163

    Re: new line in rich text box

    Welcome to VBForums

    I would use the vbNewLine constant, eg:
    Code:
    richtextbox1.text = "abcdefghijk" & vbNewLine & "lmnopqrstu"

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: new line in rich text box

    If you are adding a new line to existing text, then do
    Code:
    RichText1Box.Text = RichTextBox1.Text & "Here is the new line of text" & vbNewLine
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    951

    Re: new line in rich text box

    I would have suggested vbCrLf. Is there a difference?

  6. #6
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: new line in rich text box

    Both accomplish the same thing.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  7. #7
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    951

    Re: new line in rich text box

    Ah, allllrighty then.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,163

    Re: new line in rich text box

    In theory vbNewLine is platform specific (so for Mac/Unix would use a different character combination), but that isn't relevant to VB.

    I prefer vbNewLine as it is easier to read/remember.

  9. #9
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: new line in rich text box

    Not that it matters, but I typically use vbCrLf because it is less characters to type.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  10. #10
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    951

    Re: new line in rich text box

    ah so it's similar to locales and keyboard maps in terms of expandability?

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,163

    Re: new line in rich text box

    If you run code on Windows (which is all VB allows), vbNewLine is exactly the same as vbCrLf.

    On a Mac or Unix (so could only be VBA, perhaps in Office), it becomes whatever combination of characters is used on those OS's to indicate a new line... which may be just vbCr or just vbLf.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.