Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Macro for ordering dates chronologically in Words Documents
#11
This version can sort descending. Also, array dimensions don't have to be 0-based.

Function SortVariantArray2Dim
Code:
Copy      Help
;/
function ARRAY(VARIANT)&a col [flags] ;;flags: 1 descending

;Sorts 2-dim ARRAY(VARIANT).

;a - array variable. Not error if empty.
;col - column index (index in first dimension).


;EXAMPLE
;ARRAY(VARIANT) a.create(3 10) ;;3 columns, 10 rows
;;... (populate)
;SortVariantArray2Dim a 1 ;;sort ascending by second column



if(!a.len) ret
if(a.ndim!=2) end "must be 2-dim array"
int lb1=a.lbound(1)
if(col>a.ubound(1) or col<lb1) end "invalid column index"

int- t_sortArrCol
t_sortArrCol=col-lb1
qsort a.psa.pvData a.len a.len(1)*sizeof(VARIANT) iif(flags&1 &__SortVarArrDesc &__SortVarArrAsc)

Function __SortVarArrAsc
Code:
Copy      Help
;/
function[c]# VARIANT*a VARIANT*b

;a and b are pointer-based arays containing 1 row

int- t_sortArrCol
ret a[t_sortArrCol].cmp(b[t_sortArrCol])

Function __SortVarArrDesc
Code:
Copy      Help
;/
function[c]# VARIANT*a VARIANT*b

;a and b are pointer-based arays containing 1 row

int- t_sortArrCol
ret b[t_sortArrCol].cmp(a[t_sortArrCol])


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)