Improve performance in building large strings with a custom stringbuilder class
Building large strings can be a real performance issue in VB6. Here is a simple version of a string builder class that you can use to improve that performance a great deal.
There are lots of examples of VB6 stringbuilder classes available on the web. This one is my own version of this, but I am sure there are lots of others that are very similar or practically the same.
Option Explicit
Private m_oString() As String
Private m_oIndex As Long
Public Function Length() As Long
Length = Len(Me.ToString())
End Function
Public Sub Append(ByVal stringA As String)
m_oIndex = m_oIndex + 1
If m_oIndex = UBound(m_oString) Then
ReDim Preserve m_oString(m_oIndex + 100)
End If
m_oString(m_oIndex) = stringA
End Sub
Public Sub AppendFormat(ByVal stringA As String, ParamArray argsA() As Variant)
Dim i As Long
Dim strFormatted As String
strFormatted = stringA
For i = 0 To UBound(argsA)
strFormatted = Replace$(strFormatted, "{" & i & "}", argsA(i))
Next i
Me.Append strFormatted
End Sub
Public Function ToString() As String
ToString = Join(m_oString, vbNullString)
End Function
Private Sub Class_Initialize()
ReDim m_oString(100)
m_oIndex = -1
End Sub
