Results 1 to 9 of 9

Thread: [RESOLVED] blank line at end in richtextbox

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] blank line at end in richtextbox

    I trying to add sentences on a new line to the end of text in a richtextbox
    Like this:
    with rtb
    .selstart = len(.text)
    .seltext = vbcrlf & "some new text"
    end select
    This works okay if there is no vbcrlf already in the text i am adding to.
    If the text i am adding to has a vbcrlf at the end a blank line is added
    before my new text.
    How can i find if there is a vbcrlf and how to delete it ?
    .

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: blank line at end in richtextbox

    vb Code:
    1. if right(.text,2)=vbCrLf then .seltext = "newtext" else .seltext = vbCrLf & "newtext"

    That should work, offhand
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: blank line at end in richtextbox

    Quote Originally Posted by smUX
    vb Code:
    1. if right(.text,2)=vbCrLf then .seltext = "newtext" else .seltext = vbCrLf & "newtext"

    That should work, offhand
    Than you
    That would probably work i just need a way to select just the last line in the rtb
    Every line above the last line will have a vbcrlf

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: blank line at end in richtextbox

    using strrev(.text,vbCrLf) will give you the point at which the list vbCrLf is, but you'd then have to do other stuff to check and see if the last line is empty or not...the suggestion I gave might be the best option...that or...

    vb Code:
    1. if right(.text,2)=vbCrLf then .text=left(.text,len(.text)-2)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  5. #5

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: blank line at end in richtextbox

    Quote Originally Posted by smUX
    using strrev(.text,vbCrLf) will give you the point at which the list vbCrLf is, but you'd then have to do other stuff to check and see if the last line is empty or not...the suggestion I gave might be the best option...that or...

    vb Code:
    1. if right(.text,2)=vbCrLf then .text=left(.text,len(.text)-2)
    seems vb does not even see the vbcrlf i can see the 2 little squares in bread but
    vb does not. I might have code against the rtf code directly.
    Thought this was going to be easy

  6. #6
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: blank line at end in richtextbox

    Do me a favour and run this line of code...paste the results from the debug window here so I have an idea of what the problem is :-)

    vb Code:
    1. debug.print asc(right(.text,1)), asc(mid(.text,len(.text)-2,1))

    I think the second part is right, not 100% sure...it should return the asc codes for the linefeed first then the carriage return...10 then 13
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  7. #7

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: blank line at end in richtextbox

    Quote Originally Posted by smUX
    Do me a favour and run this line of code...paste the results from the debug window here so I have an idea of what the problem is :-)

    vb Code:
    1. debug.print asc(right(.text,1)), asc(mid(.text,len(.text)-2,1))

    I think the second part is right, not 100% sure...it should return the asc codes for the linefeed first then the carriage return...10 then 13
    debug with vbcrlf
    10 33
    without vbcrlf
    33 101

  8. #8
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: blank line at end in richtextbox

    33 = !
    101 = e
    10 you know, linefeed

    So you don't have a vbCrLf at the end, you have a Lf :-)

    Hope that helps you a little

    Edit: Whoops...just made sure of that, and code *was* wrong
    vb Code:
    1. debug.print asc(right(.text,1)), asc(mid(.text,len(.text)-1,1))
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  9. #9

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: blank line at end in richtextbox

    Quote Originally Posted by smUX
    33 = !
    101 = e
    10 you know, linefeed

    So you don't have a vbCrLf at the end, you have a Lf :-)

    Hope that helps you a little

    Edit: Whoops...just made sure of that, and code *was* wrong
    vb Code:
    1. debug.print asc(right(.text,1)), asc(mid(.text,len(.text)-1,1))
    I think i am in business i was coding against .selrtf rather than .text
    Thanks a lot

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