Class: ConCat in Category General VBA/VB6 : String Handling from Total Visual SourceBook

High performance concatenation of large strings in VBA and VB6.

When concatenating large strings on the order of 50kb or larger (for example, building an RTF string), the length of time to complete becomes exponentially longer. This is because Visual Basic re-allocates the string each time it is concatenated. This class implements an alternative to normal concatenation that does not re-allocate the string each time it is concatenated.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CConCat class.
Text Property Get the current text string. The Get method of this property trims off any text leftover in the pre-allocated internal string. This prevents up to 50k of spaces from being returned on the end of the string.
Class_Initialize Initialize Set initial values to defaults which may be overridden with property settings.
Append Method Appends a string to the end of the internal string. This function uses the trick of pre-allocating the internal string that is being appended to. This is what gives the performance benefits of this class.
' Example of CConCat
' To try this example, do the following:
' 1. Create a new form
' 2. Add a command button 'cmdTest'
' 3. Paste all the code from this example to the new form's module
' 4. Run the form

Private Sub cmdTest_Click()
  Dim ConCat As CConCat
  Dim lngCounter As Long

  Set ConCat = New CConCat

  ' set the initial string
  ConCat.Text = "Append This Text"

  ' Concatenate the string the specified number of times
  For lngCounter = 1 To 100
    ConCat.Append "Append This Text"
  Next lngCounter

  ' Display the result of the concatenation
  Debug.Print ConCat.Text

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

View all FMS products for Microsoft Access All Our Microsoft Access Products


Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info




Free Product Catalog from FMS