I guess it does it OK I'll add more data to my example of what I have. The class module appears to do about the same thing.
I ran the class example and it started out ok then got slower and slower, then it ran out of memory on my 128 MB Machine. then the Program took a massive dump and disappeared. WinNT
Here is a more detailed Example
dim ls_Row as string ' Will contain all the Data for a Row in a resultset
dim li_LenSoFar as long ' Will contain the length of the String's useful characters
dim lr_Res as rdoResultset '= a resultset <or recordset doesnt matter>
'INIT ----------
ls_Row = String$(65000, vbKeySpace) 'Gimmie some space for string.
'Assume max 255 columns * Max 255 max length per column
'MAIN ----------
if not lr_Res.EOF then
For x = 0 To lr_Res.rdoColumns.Count - 1 ' go through each column in the resultset
If IsNull(lr_Res(x)) Then
Mid$(ls_Row, li_LenSoFar + 1, 7) = "<NULL>," ' if null then give me this instead
li_LenSoFar = li_LenSoFar + 7 ' add to the count of the length
Else
ls_Col = CStr(lr_Res(x)) & ","
Mid$(ls_Row, li_LenSoFar + 1, Len(ls_Col)) = ls_Col 'go to the first Available space and add the text
li_LenSoFar = li_LenSoFar + Len(ls_Col) + 1 ' add to the count of the length
End If
Next x 'Next column
end if
'RESULTS -------
ls_Row = left$(ls_Row,li_Lensofar - 1) ' trim the last comma
msgbox ls_Row ' msgbox of a comma delimited row
'End Example
I had read that Byte Arrays would be faster.
Main Topics
Browse All Topics





by: EDDYKTPosted on 1999-08-09 at 11:48:33ID: 1530622
Paste the following to class module
------
Option Explicit
'Faster concatenation of strings in VB.
'-Dave Hng, 12 February 1999, based on Q170964 in the VB KB
'I just prefer to use Nulls instead of spaces
Private sBuffer As String
Private Const ciIncriment As Integer = 15000
Private lOffset As Long
'This function returns the concating buffer.
Public Function GetString() As String
GetString = Left$(sBuffer, lOffset)
End Function
'This function lets you assign a string to the concating buffer.
Public Sub SetString(ByRef Source As String)
sBuffer = Source & String$(ciIncriment, 0)
End Sub
'This is what does the work.
Public Sub Concat(ByRef Source As String)
Dim lBufferLen As Long
lBufferLen = Len(Source)
'If you need more space in the buffer then allocate some.
If (lOffset + lBufferLen) >= Len(sBuffer) Then
If lBufferLen > lOffset Then
sBuffer = sBuffer & String$(lBufferLen, 0)
Else
sBuffer = sBuffer & String$(ciIncriment, 0)
End If
End If
Mid$(sBuffer, lOffset + 1, lBufferLen) = Source
lOffset = lOffset + lBufferLen
End Sub
-----
On your form
Private Sub Command2_Click()
Dim clsConcat As New clsStringConcat
Dim x As Long
For x = 1 To 10000
clsConcat.Concat CStr(x) & ","
Next x
Debug.Print clsConcat.GetString
End Sub