I have an array like this:
aRezult := { cBillNumber, cName, nYear}
I need to sort on two fields cBillNumber(character element) and nYear (numeric element)
Unsorted data looks like this for example (randomly mixed years and bills):
aRezult := { 4, cName, 2011 }
aRezult := { 1, cName, 2012 }
aRezult := { 2, cName, 2012 }
aRezult := { 5, cName, 2011 }
aRezult := { 3, cName, 2012 }
aRezult := { 4, cName, 2012 }
aRezult := { 1, cName, 2011 }
aRezult := { 2, cName, 2011 }
aRezult := { 3, cName, 2011 }
aRezult := { 5, cName, 2012 }
I know how to sort data in multidimensional array if I want to sort on only one element.
In an example below, I can easily sort by BillNumber for example and get the result like this:
aRezult := { 1, cName, 2011 }
aRezult := { 1, cName, 2012 }
aRezult := { 2, cName, 2011 }
aRezult := { 2, cName, 2012 }
aRezult := { 3, cName, 2011 }
aRezult := { 3, cName, 2012 }
aRezult := { 4, cName, 2011 }
aRezult := { 4, cName, 2012 }
aRezult := { 5, cName, 2011 }
aRezult := { 5, cName, 2012 }
What I need is to sort by BillNumbers inside a year, so the result would be like:
aRezult := { 1, cName, 2011 }
aRezult := { 2, cName, 2011 }
aRezult := { 3, cName, 2011 }
aRezult := { 4, cName, 2011 }
aRezult := { 5, cName, 2011 }
aRezult := { 1, cName, 2012 }
aRezult := { 2, cName, 2012 }
aRezult := { 3, cName, 2012 }
aRezult := { 4, cName, 2012 }
aRezult := { 5, cName, 2012 }
Seems I am too tired today...
Please help
Sorting multidimenzional array
Re: Sorting multidimenzional array
Bi Boris,
You can add fourth element to the array elements:
aAdd( aRezult[i], str(aRezult[i,3],4)+str(aRezult[i,1],2) )
and the sort it by the fourth element
aOut:= ASORT(aRezult,,, { |x, y| x[4] < y[4] })
HTH
Regards, Euclides
You can add fourth element to the array elements:
aAdd( aRezult[i], str(aRezult[i,3],4)+str(aRezult[i,1],2) )
and the sort it by the fourth element
aOut:= ASORT(aRezult,,, { |x, y| x[4] < y[4] })
HTH
Regards, Euclides
Re: Sorting multidimenzional array
Yes, this was something I saw later, after I solved it this way:
aR := aSort( aRezult,,,{|x,y| If( x[3] == y[3], x[1] < y[1], x[3] < y[3] ) } )
As I said, for a moment I lost concentration and was way too tired..
Thanks for help
Boris
aR := aSort( aRezult,,,{|x,y| If( x[3] == y[3], x[1] < y[1], x[3] < y[3] ) } )
As I said, for a moment I lost concentration and was way too tired..
Thanks for help
Boris