Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Keeping an array sorted
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00434680
Message ID:
00434811
Views:
20
>I can't seem to get my brain around this one today, so I was hoping to borrow the group brains for a while. :)
>
>I have an array: laOrder[6]. Each element contains a number 1-6. But I only want each number used once. I start with this:
>
>laOrder[1] = 1
>laOrder[2] = 2
>laOrder[3] = 3
>laOrder[4] = 4
>laOrder[5] = 5
>laOrder[6] = 6
>
>If I do this:
>
>laOrder[3] = 1
>
>I want the rest to renumber themselves, but keep the same order:
>
>laOrder[1] = 5
>laOrder[2] = 6
>laOrder[3] = 1
>laOrder[4] = 2
>laOrder[5] = 3
>laOrder[6] = 4
>
>Is there a simple way to do this? It seems like it shouldn't be hard, but my brain is acting like it does when I think about recursion. LOL!
>
>Thanks,
>
Michelle,

Try
LPARAMETERS tsubscript, tvalue, ta_array


LOCAL lni, lnlast, lnvalue
lnlast = ALEN(ta_array, 1)
lnvalue = tvalue
FOR lni = tsubscript TO lnlast
  ta_array[lni] = lnvalue
  lnvalue = lnvalue + 1
NEXT
IF tsubscript > 1
  FOR lni = 1 TO tsubscript - 1
    ta_array[lni] = lnvalue
    lnvalue = lnvalue + 1
  NEXT
ENDIF
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform