Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sort 2-Dim Array other than on 1st elem in row (eg for Date)
#1
Hello Gintaras,
Hope all is well - I haven't posted in a long while but still am an avid QM-user!

Is it possible to sort on a 2-dim array other than on first element in each row.
I have a Date string as the 4th 'column' and want to sort on that rather than what goes into the 1st column.
This would be similar to the DlgGrid.Sort function with flags 128 for date and 0x100 (most recent to older i.e. descending).

e.g. g.Sort(128|0x100 3)
for flags as above and 3 for 4th 0th-order column

I saw this in help file:

Quote:QM 2.3.2. Supports multi-dimension arrays. Sorts rightmost dimension.

When sorting multi-dimension array, compares first element for each indice of rightmost dimension. For example, if the array has 2 dimensions, where the first used for columns and the second for rows, the function compares the first element in each row. When using callback function, the function receives reference to that element. To compare other element, adjust references as in the example.



Code:
Copy      Help
function# param str&a str&b

;initially a and b are elements in column 0

&a=&a+(2*sizeof(a))
&b=&b+(2*sizeof(b))

;now a and b are elements in column 2 ...


but don't know how to apply. Could you supply an example?

Thanks so much!,
S
#2
ret StrCompare(a b) ;;or StrCompare(b a)
#3
Thanks!

I made my 'other column' sortfunction like this (where I intend to sort on the 3rd column):

Function DateColumnSort
Code:
Copy      Help
;/
function# param str&a str&b

&a=&a+(3*sizeof(a))
&b=&b+(3*sizeof(b))
ret StrCompare(b a)

Then I call it as such (for a descending (most recent first) date sort on the values in zero-order column 2 (3rd column):

Code:
Copy      Help
ARRAY(str) arrGrid ;; filled with dates in zero-order column 2 (3rd column)
str d
arrGrid.sort(1|0x100 DateColumnSort  &d )

It seems to be working!
Thanks so much,
S


Forum Jump:


Users browsing this thread: 2 Guest(s)