Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCompare the speeds of TextBox, RichTextBox, and the MS Forms 2.0 TextBox
KeywordsTextBox, speed, performance, TextBox, RichTextBox, MS Forms 2.0
CategoriesControls, Tips and Tricks
 
Thanks to Ivan Andonov.

This program sets the text in three kinds of TextBoxes a bunch of times to see which is fastest. In one test loading 16KB of text, the RichTextBox took 0.05 seconds, the Forms text box took 0.11 seconds, and the VB 6 TextBox took 3.3 seconds!

The conclusion: If you need to display strings quickly, don't use the normal Visual Basic TextBox. You might want to perform some tests that more closely mimic what your application needs to do, however.

The following code shows the RichTextBox's test procedure. The others are similar.

 
' Puts strings into a Rich textbox and times it.
Private Sub cmdTryRichTextBox_Click()
Dim i As Long
Dim buf As String

    On Error GoTo theErr
    EnableButtons False
    RichTextBox1.Text = ""
    tSTART = Timer
    '----------------------------------------
        For i = 1 To iLim
            buf = buf & str1KB ' 1K at a time
            RichTextBox1.Text = buf
        Next i
    '----------------------------------------
    tEND = Timer
    MsgBox "Elapsed: " & Format(tEND - tSTART, "#,##0.00") _
        & " seconds"
    EnableButtons True
    Exit Sub

theErr:
    MsgBox "Error: " & Err.Description & vbCrLf & "Len(buf) " & _
        "= " & Len(buf)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated