Hello!
By using this code you can simply move a 2d string arrays one indexed dimension into a single dimension array.Code:Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long) Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (dst As Any, ByVal iLen&) Dim X As Long, Y As Long ReDim Source(0 To 500, 0 To 5) As String For X = 0 To 5 For Y = 0 To 500 Source(Y, X) = "Item " + CStr(Y) + " in col " + CStr(X) Next Y Next X ReDim out(UBound(Source, 1)) As String CopyMemory ByVal VarPtr(out(0)), ByVal VarPtr(Source(0, 2)), 4 * (UBound(out) + 1) ZeroMemory ByVal VarPtr(Source(0, 2)), 4 * (UBound(out) + 1) Erase Source MsgBox "125th element: " + out(124) + vbNewLine + "126th element:" + out(125) End
But if you change the variable type to Variant, everything goes to wrong. It copies the first 125 element (0-124), but after the 125th element it copies only null strings.
Do you have any ideas how can i fix this code?
Ok ive found it. Variant type string variants has 8 byte long pointers, but strings has 4. So i have to copy the 8 byte long pointers to get it to work.![]()




Reply With Quote