Results 1 to 8 of 8

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

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    743

    Resolved [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. #2
    Addicted Member
    Join Date
    Jan 2018
    Posts
    219

    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. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    743

    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. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,425

    Re: ReIndex Offets Right to Left AND Left to Right

    Quote Originally Posted by vb6forever View Post
    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.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    813

    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. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    743

    Re: ReIndex Offets Right to Left AND Left to Right

    ahenry and Elroy: Thanks for responding.

    I'll close this.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,803

    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. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,499

    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
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

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



Click Here to Expand Forum to Full Width