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
    41,929

    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

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

    Re: new line in rich text box

    I would have suggested vbCrLf. Is there a difference?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: new line in rich text box

    Both accomplish the same thing.

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

    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
    41,929

    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: new line in rich text box

    Not that it matters, but I typically use vbCrLf because it is less characters to type.

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

    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
    41,929

    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
  •  



Click Here to Expand Forum to Full Width