Sort 2-Dim Array other than on 1st elem in row (eg for Date)

Functions, classes, components, etc. Only high quality content.

Sort 2-Dim Array other than on 1st elem in row (eg for Date)

Postby stupomer on Fri Sep 29, 2017 1:43 pm

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:

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.




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
User avatar
stupomer
Active Member
 
Posts: 925
Joined: Fri Mar 23, 2007 2:22 am
Location: Boston, USA

Re: Sort 2-Dim Array other than on 1st elem in row (eg for Date)

Postby Gintaras on Fri Sep 29, 2017 1:55 pm

ret StrCompare(a b) ;;or StrCompare(b a)
Gintaras
Site Admin
 
Posts: 10385
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Sort 2-Dim Array other than on 1st elem in row (eg for Date)

Postby stupomer on Fri Sep 29, 2017 8:40 pm

Thanks!

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

Function DateColumnSort     ?
;/
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):

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
User avatar
stupomer
Active Member
 
Posts: 925
Joined: Fri Mar 23, 2007 2:22 am
Location: Boston, USA


Return to QM Extensions

Who is online

Users browsing this forum: No registered users and 2 guests

cron