Code:
DIM ArrayStart(1 to 100) As Global Long '// Where the data starts DIM ArrayLen(1 to 100) As Global Long '// How much data there is DIM ArrayData(1 To 10000) As Global Long '// The data array DIM g_Position As Global Long Sub MakeArray(index As Long, vSize As Long) Dim vStart As Long Dim v As Long vStart = g_Position + 1 If (vStart + vSize) > UBound(ArrayData) Then v = UBOUND(ArrayData) + vSize + 1000 Redim Preserve ArrayData(1 To v) End If If index > UBound(ArrayStart) Then v = index + 1000 Redim Preserve ArrayStart(1 To v) Redim Preserve ArrayLen(1 To v) End If ArrayStart(index) = vStart ArrayLen(index) = vSize g_Position = g_Position + vSize End Sub Sub WriteArray(index As Long, vElement As Long, vValue As Long) ArrayData(ArrayStart(index) + vElement - 1) = vValue End Sub Function ReadArray(index As Long, vElement As Long) As Long ReadArray = ArrayData(ArrayStart(index) + vElement - 1) End Function '// '////Using the sub: '// I will make 4 arrays of 4 different sizes MakeArray 1, 177 'Array 1 has 177 elements MakeArray 2, 188 MakeArray 3, 200 MakeArray 4, 19 '// '// '// I will write data to the array WriteArray 1, 56, 13 '// Write to array 1, set element 56 to a value of 13 WriteArray 3, 199, 1 '// Read data from the array i = ReadArray(1, 56) '// Read array 1 element 56
Leave a comment: