Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sorting a Multi Dimension by column
Message
De
01/05/2006 08:14:59
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01117945
Message ID:
01117981
Vues:
19
This message has been marked as the solution to the initial question of the thread.
>Hi Guys,
>I had a utility to sort on column 2 of a multi dimension array, I have lost the code, Its been about 10 years since I wrote it I need to jolt my brain does anyone have code.

Fred,
I think you meant multicolumn sorting.
Asort(myarray) && Sort on 1st col
axsort(@myarray,1,5,1) && Sort on 5th desc - keep previous sort
axsort(@myarray,5,2)   && Sort on 2nd - keep previous sort


******************
*!*	function axSort
*!*	Extended array sort
*!*	taSortArray - Array to sort passed by ref
*!*	tnKeepColumn - Column number that's already sorted on
*!*	tnSortColumn - Column to sort
*!*	tnDirection - Omitted or 0 ascending, else descending
******************
Function axsort
  Lparameters taSortArray, tnKeepColumn, tnSortColumn, tnDirection
  tnDirection = iif(empty(m.tnDirection),0,1)
  lnRows = alen(m.taSortArray,1)
  lnRows2Sort=0
  lnSortStart = m.tnSortColumn
  luElem = taSortArray[1,m.tnKeepcolumn]
  For ix=1 to m.lnRows
    If taSortArray[m.ix,m.tnKeepcolumn] # luElem
      Asort(m.taSortArray,m.lnSortStart, m.lnRows2Sort, m.tnDirection)
      lnSortStart = (m.ix-1)*alen(m.taSortArray,2)+m.tnSortColumn
      lnRows2Sort = 1
      luElem = taSortArray[m.ix,m.tnKeepcolumn]
    Else
      lnRows2Sort = m.lnRows2Sort+1
    Endif
  Endfor
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform