• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Add text to top line of textbox

Awww, this has got to be so easy but it's driving me nuts due my lack of VB skills!!

I'm working on a kind of messenger program for work. All I need to do is to have the newest messages at the top of the richtext box. Simple eh!! As I'm working with rich text font, and colour formatting, I'm having to use selstart and sel length to add my text, otherwise the formatting is lost.

This is what I'm doing. I've tried adding VBCRLF's but nothing seems to work. Please point out what I'm doing wrong. I've been staring at this screen fo so long, I thing I've gone code blind!!

     Dim Data As String
     WinSockMessage.GetData Data                             'Get our incoming data from our winsock control.....
     TextBuffer.TextRTF = Data                                   'and store it in our TextBuffer textbox

    TextBuffer.SelStart = 0
    TextBuffer.SelLength = Len(TextBuffer.Text)           'Get the length of the text in the TextBuffer..........

    MessageIN.SelStart = 0
    MessageIN.SelLength = 0
    MessageIN.SelRTF = TextBuffer.SelRTF                  'and add it to the start of the MessageIN textbox
0
wildarmsdave
Asked:
wildarmsdave
  • 3
  • 2
  • 2
  • +2
1 Solution
 
nffvrxqgrcfqvvcCommented:
I am not exactly sure what you mean but I have an idea, do you mean when the you have to scroll down to view the last message(or line sent) with the scrollbar. I suppose this is what you mean.

In richtextbox_Change add this line:
'That will scroll to the end of the textbox.

RichTextbox1.SelStart = Len(RichTextBox1)
0
 
nffvrxqgrcfqvvcCommented:
My first comment scrolls to the last message sent which seems logical for a chat, but if you want to set the text at the top You can just switch it to this

Add to Richtextbox_Change

RichTextbox1.SelStart = 0 or 1
0
 
ShauliCommented:
I guess there is text already in MessageIN, and you want to add text in front of the first line. If this is the case then you must store the current text in a variable, and add both back. Something like:

MessageIN.SelRTF = TextBuffer.SelRTF & vbCrLf & myStoredText

S
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
wildarmsdaveAuthor Commented:
Shauli, you are the closest with what I want to do but I've already tried what you suggested and it didn't work....

To explain myself a little more....

On a normal chat prog, if a someone sends 3 messages in this order eg, 1111, 2222, 3333. This would appear on screen as in the example below (because newest messages tend to be added to the bottom of existing messages.)

1111  (oldest message)
2222
3333  (newest message)

I need to do it the other way round, i.e newest messages to the top so my version would read...

3333  (newest message)
2222
1111

All I can get to happen in the MessageIn windows is this...........

333322221111

It doesn't seem to recognise a VBCRLF???
0
 
Richie_SimonettiIT OperationsCommented:
sorry but i am confuzed.
is not enought this?
TextBuffer.TextRTF =<new_text_goes_here> & TextBuffer.TextRTF
0
 
nffvrxqgrcfqvvcCommented:
Then u use this line

send a vbcrlf before anything else and start from 0

RichTextbox1.SelStart = 0
0
 
ShauliCommented:
Where in your code do you add the vbCrLf. I can't find it. btw, is the MultiLine property set to True?

S
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It should simply be:

    MessageIN.SelStart = 0
    MessageIN.SelLength = 0
    MessageIN.SelText = TextBuffer.TextRTF & vbCrLf

UNLESS you have multiple messages in your TextBuffer.  In that case you would need to walk the TextBuffer RTB backwards and add each msg to your MessageIN RTB so that the messages appear with the newest at the top.
0
 
wildarmsdaveAuthor Commented:
Spot on Idle Mind. It was the last line that was causing the problem. The .SelText part of the code wouldn't allow a vbCrlf. Once I changed it to .textRTF it worked fine. I cannot believe that I overlooked that.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now