[quote=52336:@Kem Tekinay]Here is some code I haven’t tested that should do the job you’re seeking. You already have a string array that you want to reorder by moving a range defined by startIndex and count to another location within the array. In your example, you’d call it as MoveRange( array1, 1, 2, 7 )
, meaning, take the items at index 1 and 2 and move them to index 7, shifting everything else in the array up. In this code, it won’t matter if array1 has a Ubound of 8 or 8000. However, if Ubound is less than 8, you will get unexpected results.
[code]
Sub MoveRange (arr() As String, startIndex As Integer, count As Integer, destinationIndex As Integer)
dim indexArr() as Integer // The array that will determine the final order
redim indexArr( arr.Ubound ) // Same size as the string array
dim buffer as integer = 10
while buffer <= count
buffer = buffer * 10
wend
for i as integer = 0 to indexArr.Ubound
indexArr( i ) = i * buffer // Fill in the index array as 0, 10, 20, …
next i
// Adjust the indexes
dim lastIndex as integer = count - 1
for i as integer = 0 to lastIndex
indexArr( startIndex + i ) = ( destinationIndex * buffer ) + i + 1 // The new indexes will be 71, 72
next i
// At this point, the index array will look like 0, 71, 72, 30, 40, 50, 60, 70, 80, 90,
indexArr.SortWith( arr ) // Sort the indexArr and the string array along with it
// Now the indexArr will be 0, 30, 40, 50, 60, 70, 71, 72, 80, 90,
// and the elements in arr will match that order.
End Sub
[/code][/quote]
Wow, don’t know if this works with what I am trying to do and the data types I am using but if this code works then excellent. Thankyou for your amazing help. I love how you sent me a method to simplify things to the extreme, good work!!