small idea for
Long lCount = Array Add arrayvariable2 Into arrayvariable1
in example below array sArray1() will thereafter contain all the members of sArray1() and sArray2() together.
sArray2 is empty then.
i needed a few times something as this to fast join 2 arrays of strings,
this only works for dynamic string-array, other types should be easy to realize...
could also be Add$ for Strings & Add for other types but i guess thinCore will know the type...
maybe something for new Keyword Into,
optional switches as Unique or Ascend/Descend thinkeable
Array Add [Unique] v2 [,Collate Ucase][,Ascend | Descend] Into v1
Uses "console"
' --------------------------------------------------------------------
Function Array_Add(ByRef a1() As String, _
ByRef a2() As String _
) As Long
' --------------------------------------------------------------------
' will move all elements of a2 into a1
' a2 will be empty thereafter
' returns Ubound of a1
If UBound(a2) = 0 Then Return Ubound(a1)
ReDim Preserve a1(UBound(a1) + UBound(a2))
Memory_Swap( _
VarPtr(a1(1)) + 4 * ( UBound(a1) - UBound(a2) ), _
VarPtr(a2(1)), _
4 * UBound(a2) )
Function = UBound(a1)
End Function
' now test it:
' --------------------------------------------------------------------
Function TBMain()
' --------------------------------------------------------------------
Local sArray1(3) As String
Local sArray2(5) As String
Local i As Long
For i = 1 To UBound(sArray1)
sArray1(i) = "array1(" & TStr$(i) & ")"
Next
For i = 1 To UBound(sArray2)
sArray2(i) = "array2(" & TStr$(i) & ")"
Next
i = array_Add(sArray1, sArray2)
While i
i -= 1
PrintL sArray1(UBound(sArray1) - i )
Wend
For i = 1 To UBound(sArray2)
PrintL i, sArray2(i)
Next
PrintL "key to end"
WaitKey
End Function
Bookmarks