# Thread: [RESOLVED] ReIndex Offets Right to Left AND Left to Right

1. ## [RESOLVED] ReIndex Offets Right to Left AND Left to Right

Hoping someone might have an efficient function already written to do this.

For Example:

Code:
```Original Offset from Far Right (start at 0)
4        3      2      1     0
N+4,  N+3, N+2, N+1, N

ReIndex Offset from Far Left (start at 0)
N = 4
N-4, N-3, N-2, N- 1, N
0        1     2     3     4```

2. ## Re: ReIndex Offets Right to Left AND Left to Right

I don't know what you are trying to do here, but integer comparisons and arithmetic are going to be efficient no matter how you code it. What do you get from using functions for this, is there some sort of bounds-checking needed?

3. ## Re: ReIndex Offets Right to Left AND Left to Right

What I'm after is there a more efficient way to find the reversed index order value. When plotting things, a lot of time I need to plot forward and backward.

Code:
```Function CIndex2LeftBased(ByVal idxUBoundRightBased As Long, idxRightValue As Long)
'Change Right zero based index to Left Based Zero
CIndex2LeftBased = idxUBoundRightBased - idxRightValue
End Function```

4. ## Re: ReIndex Offets Right to Left AND Left to Right

Originally Posted by vb6forever
When plotting things, a lot of time I need to plot forward and backward.
I'm not sure what you mean either, but, as ahenry says, integer (Long or Integer) math is lightening fast, especially addition and/or subtraction. It's all done in CPU registers, trivial stuff. Are you talking about "the time to code it?" If so, then I'm not sure what to say.

Bottom line, just do the math and get it done.

5. ## Re: ReIndex Offets Right to Left AND Left to Right

Assuming your values are all in an array
You would just use a for loop where you set
The start, end, and step variables appropriately

Count down would be step -1 normal step =1

6. ## Re: ReIndex Offets Right to Left AND Left to Right

ahenry and Elroy: Thanks for responding.

I'll close this.

7. ## Re: [RESOLVED] ReIndex Offets Right to Left AND Left to Right

It sounds like you want to sort in ascending order.

if you "offsets" are in an array it is pretty compact and easy to code. With such a small population of values even the simplest of sort algorithms should be performant enough for many things.

8. ## Re: [RESOLVED] ReIndex Offets Right to Left AND Left to Right

Something like this?
Code:
```Public Function ReverseArray(ByRef AArray() As Variant) As Variant()
Dim lb As Long
Dim ub As Long
Dim ublb As Long
Dim iNext As Long
Dim tmp As Variant
Dim i As Long
lb = LBound(AArray)
ub = UBound(AArray)
ublb = ub + lb
For i = lb To ublb / 2
iNext = ublb - i
tmp = AArray(iNext)
AArray(iNext) = AArray(i)
AArray(i) = tmp
Next
ReverseArray = AArray
End Function```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•