Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleDisplay a 10 line scrolling log
Keywordslog, limit, scroll
CategoriesTips and Tricks
 
When you add a new line to text in a TextBox, count the carriage returns from beginning to end. When you get to number 10, chop off the rest of the log string.
 
Private Sub AddLogLine(ByVal new_text As String)
Const MAX_LINES = 10

Dim all_text As String
Dim num_cr As Integer
Dim pos As Integer

    ' Add the new text at the end of the current text.
    all_text = txtLog.Text & vbCrLf & new_text

    ' Count the carriage returns from back to front.
    pos = InStrRev(all_text, vbCrLf)
    Do While pos > 0
        num_cr = num_cr + 1
        If num_cr >= MAX_LINES Then
            ' Stop here.
            all_text = Mid$(all_text, pos + 2)
            Exit Do
        End If
        pos = InStrRev(all_text, vbCrLf, pos - 2)
    Loop

    ' Display the results and scroll to the bottom.
    txtLog.Text = all_text
    txtLog.SelStart = Len(txtLog.Text)
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated