Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox scrolling

Status
Not open for further replies.

AdaHacker

Programmer
Sep 6, 2001
392
US
As part of an app I'm writing that utilizes a modem, I need to have some simple terminal emulation. It works perfectly, except for one thing. When I recieve data, I append it to a RichTextBox with a line like
Code:
RTBox.Text=RTBox.Text & data[\code]
 and I'd like the user to be able to see the incoming data as it goes in, i.e. I want the box to scroll down automatically as more data is put into it.  
Normally, whenever you change the .text property, the cursor goes back to the very first line, so I put the following in the change event:
[code]
    Output_box.SelStart = Len(Output_box.Text)
    Output_box.SelLength = 0
[\code]
This forces the cursor to the bottom of the box, but it doesn't work too well when I'm adding lots of data very fast.  The box starts to flicker and it just generally gets ugly.  
There has to be a better way to do this.  Anyone have any ideas?
 
hie,
Instead of using
"RTBox.Text=RTBox.Text & data"
use code written below :

RTBox.SelStart = Len(RTBox.Text)
RTBox.SelText = data

U can also add "crlf" for moving cursor to next line
like this
RTBox.SelStart = len(RTBox.Text)
RTBox.SelText = data & Crlf

hope this may help you.





 
One other note. Using Len(RTBox.Text) causes the entire contents of the RTF to retrieved into a temporary string just to execute the Len function. This can slow you down considerably on a large RTF (I've used 100K+). If instead, you set SelStart to a value higher than the # of characters in the RTF, the RTF resets SelLength to the actual end so...

rtf.SelStart = 200000000
is faster in positioning at the end.

If you want to know the length of the RTF then
Dim lngLen as long
rtf.SelStart = 200000000
lngLen = Rtf.SelLStart Compare Code (Text)
Generate Sort in VB or VBScript
 
Well, thanks for the help guys. I tried a combination of your solutions, but I don't think things are really any better. Rather than use the change event, I moved the scrolling code into the OnComm event and used getimran's suggestion for the text appending. Here's some of my code:
Code:
Output_box.SelStart = 200000000
rtflen = Output_box.SelLength
Output_box.SelStart = Len(Output_box.Text)
Output_box.SelText = inbuff
The scrolling is much, much nicer now. Unfortunately, when the text is displayed, it quite often gets corrupted. When I scroll it out of the visible section and come back, it's fine. It's just that the initial display somehow turns to garbage, which kind of defeats the purpose.
Any ideas?
 
If you use
Output_box.SelStart = 200000000
you do not need
Output_box.SelStart = Len(Output_box.Text)
and
rtflen = Output_box.SelLength
is useless when appending data because SelStart is at the end and there can be no SelLength (RTF will reset it to 0).
Compare Code (Text)
Generate Sort in VB or VBScript
 
Ack. You're absolutely right. I don't know what I was thinking. Now that I stop to look at it, that code didn't make any sense at all. I guess my brain just decided to take a long lunch. Oh well.
Anyway, thanks a lot. I'm glad one of us was paying attention. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top