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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Boxes and Scroll Bars 1

Status
Not open for further replies.

rjr9999

Programmer
Apr 7, 2001
183
US
Ok, as per my prior post, i'm writing a telnet application. I have the data streeming in fine now, but I need suggestions as to how I can get the text box (it's a standard text box) to display the most recent info, without me haveing to scroll down. Also, I don't want more than 10000 MAX in the text box, but if I set the max thing that's on there, it cuts off from the most recent...is there a way to cut off from the LEAST recent? Any help here is appreciated.

Rob
 
I tried this little number

Text1.SelStart = Len(Text1.Text)

It's WAY too slow...is there any other way?
 
Text1.SelStart = Len(Text1.Text)
extracts the contents of the textbox into a string then applies the Len function.
Try this
Text1.SelStart = 65535
Debug.Print "Start=" & Text.SelStart

If Selstart is set beyond the number of bytes in a textbox then the textbox resets it to the actual number of bytes. "Correct" way to find how many characters are in a textbox (or RichTextBox) is
Text.SelStart = 65535
lngLen = Text.SelStart
RTB.SelStart = 99999999
lngLen = RTB.SelStart

While we are at it
text1.Text = Text1.Text & strNewstuff
is a waste, especially if it holds a large number of bytes.
Better is
text1.SelStart = 65535
text1.SelRext = strNewstuff

 
Ah, very nice, thanks for that tid bit...while we're on the subject...what happens if I want to start cutting off old output after 30000? Eg. You can't scroll up and see 100 if you're on 35000...What's flowing through my mind is basically,

if len(text1.text) > 30000 then
BufOverFlow = (len(text1.text) - 30000)
text1.selstart = 1 (or would this be 0?)
delete from selstart to BufOverFlow (how?)
end if

again, any help would be appriciated ;)
 
First, I think you missed something in my post.
Do not use LEN on a large textbox. It has to extract the entire contents into a string just to get the length. AND if you are bent on using it, do not use it twice in the same statement.
Code:
Sub AddText (Text1 as textbox, byval strNewstuff as string)
    Dim lngLen    as long
    Dim lngDiff   as long

    text1.SelStart = 65535
    lngLen = text1.SelStart
    lngDiff = lngLen + Len(strNewstuff) - 30000  
    if lngDiff > 0 then
        text1.SelStart = 0
        text1.SelLength = lngDiff ' Length to delete
        text1.SelText = ""        ' replace with 0 length
    End if
    text1.SelStart = 65535   ' resets SelLength to 0
    text1.SelText = strNewStuff ' add new at end
End Sub
Now your only problem is to locate the first CrLF in the textbox whose offset is greater than the number of characters to take off the front else your first line might be a partial line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top