Results 1 to 9 of 9

Thread: Adding up text in RichtextBox

  1. #1

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    640

    Adding up text in RichtextBox

    1. Why does the text not add up in the following statement?

    Code:
    rtbComplaintHistory.TextRTF = rtbComplaintHistory.TextRTF & vbCrLf & "Added by '" & UserName & "' on '" & Format(Date & " " & Time, "dd-MMM-yy HH:mm") & "'" & vbCrLf & rtbComplaintInput.TextRTF
    2. Why does rtbTest.textrtf="" not clear the textbox.

    Thanks
    PK
    Last edited by Peekay; Jul 2nd, 2021 at 02:21 AM.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,709

    Re: Adding up text in RichtextBox

    @Question 1: https://www.vbforums.com/showthread....-a-RichTextBox
    @Question 2: RichTextBox.Clear-Method?
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,956

    Re: Adding up text in RichtextBox

    Date() and Time() return Date values, not String values. And I think you really want Now() here anyway.

    All covered in That Fine Manual.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,527

    Re: Adding up text in RichtextBox

    Quote Originally Posted by Peekay View Post
    2. Why does rtbTest.textrtf="" not clear the textbox.
    Try rtbTest.Text = "" instead.


    Quote Originally Posted by Peekay View Post
    1. Why does the text not add up in the following statement?

    Code:
    rtbComplaintHistory.TextRTF = rtbComplaintHistory.TextRTF & vbCrLf & "Added by '" & UserName & "' on '" & Format(Date & " " & Time, "dd-MMM-yy HH:mm") & "'" & vbCrLf & rtbComplaintInput.TextRTF
    Try (not tested):

    Code:
        rtbComplaintHistory.SelStart = Len(rtbComplaintHistory.Text)
        rtbComplaintHistory.SelText = vbCrLf & "Added by '" & UserName & "' on '" & Format(Date & " " & Time, "dd-MMM-yy HH:mm") & "'" & vbCrLf
        rtbComplaintHistory.SelRTF = rtbComplaintInput.TextRTF

  5. #5

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    640

    Re: Adding up text in RichtextBox

    Thanks all you guys, I appreciate.

    I am just further strengthened in my view that it is a PoorTextBox.
    I have decided to use it as a plain text box as it has the locked property which I like better than the disabled property of the plain Textbox.
    End of story. It is not worth the effort. Sort of diminishing returns as in economics.
    However, it was an interesting excursion into the domain of a control that is not worth the form it is written on.

    PK
    Last edited by Peekay; Jul 3rd, 2021 at 04:20 AM.

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,765

    Re: Adding up text in RichtextBox

    The normal Textbox also has a locked property

  7. #7

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    640

    Re: Adding up text in RichtextBox

    Thanks Arnoutdv, I did not know that.
    PK

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: Adding up text in RichtextBox

    The RTB has its upside. I rarely use it but when you need formatted text displayed, multi colors, some bold, italic, underlined, different fonts and/or font sizes the RTB is the way to go. It also allows you to create, save and load easily rtf documents and it can handle much larger text than a standard text box so if any of these are needed it is the tool to use.

    If on the other hand a standard text box meets your needs then by all means use the standard text box. The RTB should be used only when you need one or more of its extended abilities.

  9. #9

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    640

    Re: Adding up text in RichtextBox

    DataMiser,
    I can get away with a Textbox, but that would be par for the course and formatted text would be PGA league, but then I need to print formatted text as well. I am not there yet.
    It is strange that there is so little help on the internet with this. I presume more people is snubbing it than using it.
    PK

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