Guus2005
AWF VIP
- Local time
- Today, 20:16
- Joined
- Jun 26, 2007
- Messages
- 2,642
I have a lot of concatenations to do so i used a class to do that more efficiently.
clsBuildString
It uses a collection to store every string and then joins everything together. Which should be faster than x = a & b & c.
When i debug the code i notice that new items are not created and all added strings are concatenated to the first one.
In the end that is what i wanted but i find it odd that the code doesn't do what it is supposed to do.
But perhaps i am doing something wrong?
The clsBuidString code is from the internet.
I have attached an example database with the code.
To test the functionality.
	
	
	
		
The class clsBuildString
	
	
	
		
 clsBuildString
It uses a collection to store every string and then joins everything together. Which should be faster than x = a & b & c.
When i debug the code i notice that new items are not created and all added strings are concatenated to the first one.
In the end that is what i wanted but i find it odd that the code doesn't do what it is supposed to do.
But perhaps i am doing something wrong?
The clsBuidString code is from the internet.
I have attached an example database with the code.
To test the functionality.
		Code:
	
	
	Public Sub CollectionTest()
'Exporteren van de data.
    Dim strLine As New clsBuildString
  
    strLine.Add "1000S0000"
    strLine.Add "999"
    strLine.Add "FOO"
    strLine.Add "!!!"
    strLine.Add "BAR"
  
    Debug.Print strLine.Text
End Sub
		Code:
	
	
	Private mcolStrings As Collection
Private mstrDelim As String
Private Sub Class_Initialize()
    Set mcolStrings = New Collection
    Delim = ""
End Sub
Private Sub Class_Terminate()
    Set mcolStrings = Nothing
End Sub
Public Property Get Delim() As String
    Delim = mstrDelim
End Property
Public Property Let Delim(ByVal strNewValue As String)
    mstrDelim = strNewValue
End Property
Public Property Get Text() As String
    Dim lngNext As Long
    Dim strStrings() As String
    Dim varItem As Variant
    Dim strText As String
  
    Select Case mcolStrings.Count
        Case 0
            Text = vbNullString
        Case 1
            Text = mcolStrings(1)
        Case Else
            ReDim strStrings(1 To mcolStrings.Count)
            For Each varItem In mcolStrings
                lngNext = lngNext + 1
                strStrings(lngNext) = varItem
            Next
            Set mcolStrings = Nothing
            Set mcolStrings = New Collection
            strText = Join(strStrings, mstrDelim)
            mcolStrings.Add strText
            Text = strText
    End Select
End Property
Public Property Let Text(ByVal strNewValue As String)
    Set mcolStrings = Nothing
    Set mcolStrings = New Collection
    mcolStrings.Add strNewValue
End Property
Public Function Add(ByVal strNewValue As String)
    mcolStrings.Add strNewValue
End Function 
	 
 
		 
 
		 
 
		