|
-
Feb 4th, 2016, 07:44 AM
#1
Thread Starter
Member
re-ordering array indices not working; is there a better way?
This VB6 code is supposed to re-order the elements in array 'EngRusArr' and copy them to array 'RusEngArr'
The math behind how the elements are swapped is simple; every third element 'jumps' back 2 positions, and the previous 2 move forward to fill the 'gaps' so to speak. That bit works, but...
ReDim RusEngArr(1 To UBound(EngRusArr))
For orig = 1 To (UBound(EngRusArr) + 0)
indx = orig / 3
If indx = Int(indx) Then swap = orig - 2
If indx <> Int(indx) Then swap = orig + 1
ReDim RusEngArr(swap)
RusEngArr(swap) = EngRusArr(orig)
Next orig
For p = LBound(RusEngArr) To UBound(RusEngArr)
InkEdit6.Text = InkEdit6.Text & vbNewLine & RusEngArr(p)
Next p
...In the second loop, all the array elements are empty. All the information that was in the original array hasn't stayed in the new one. Is there something wrong with my 2nd redim statement?
Is there a simpler/better/functional way to do this? Simply using the existing 'If' statemnts to 'sort' the original array, and then make it equivalent to the new array, would be fine. I just can't work out how to do this from what I've seen of 'sorting' code.
Last edited by moorea21; Feb 4th, 2016 at 07:50 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|