What type is in these fields?
The best way to do this is converting both to text of the same size.
Ex:
Code: Select all
//-- 1: Code, 2: Last Name, 3: First Name
aBitem := {}
aAdd( aBItem, {1, PadR( "FIELDS", 25 ), PadR("ROBERT",20) } )
aAdd( aBItem, {2, PadR( "BARROW", 25 ), PadR("SARAH",20) } )
aAdd( aBItem, {3, PadR( "FIELDS", 25 ), PadR("ANTHONY",20) } )
//-- Sort by last name
aSort( aBitem,,, {|x,y| ( x[2]+x[3] ) < ( y[2]+y[3] ) } )
? AllTrim( aBItem[1,2] ) + AllTrim( aBItem[1,3] ) //-- BARROW SARAH
? AllTrim( aBItem[2,2] ) + AllTrim( aBItem[2,3] ) //-- FIELDS ANTHONY
? AllTrim( aBItem[3,2] ) + AllTrim( aBItem[3,3] ) //-- FIELDS ROBERT
//-- Sort by first name
aSort( aBitem,,, {|x,y| ( x[3]+x[2] ) < ( y[3]+y[2] ) } )
? AllTrim( aBItem[1,3] ) + AllTrim( aBItem[1,2] ) //-- ANTHONY FIELDS
? AllTrim( aBItem[2,3] ) + AllTrim( aBItem[2,2] ) //-- ROBERT FIELDS
? AllTrim( aBItem[3,3] ) + AllTrim( aBItem[3,2] ) //-- SARAH BARROW
//-- Sort by code
aSort( aBitem,,, {|x,y| ( x[1] ) < ( y[1] ) } )
? AllTrim( aBItem[1,3] ) + AllTrim( aBItem[1,2] ) //-- ROBERT FIELDS
? AllTrim( aBItem[2,3] ) + AllTrim( aBItem[2,2] ) //-- SARAH BARROW
? AllTrim( aBItem[3,3] ) + AllTrim( aBItem[3,2] ) //-- ANTHONY FIELDS