Function overview
Prototype
SortList (
ValueList; Sort; Type )
Parameters
ValueList ValueList List for sort - ValueCount ( ValueList ) ≤ 100000
Sort Empty or
Type Empty or
Description
Tags:
value list sort
// SortList ( ValueList ; Sort ; Type ) v2.0
// Carrefull : Parameter is : ValueList ; Sort ; Type and not ValueList ; Type ; Sort
// If you change the name "SortList", also change in the variable $sl_Exe
/*
No dependance. Recursive CustomFunction .....
To sort a list
-> ValueList List for sort - ValueCount ( ValueList ) ≤ 100000
-> Sort : Empty or "Asc" or "Des" [Empty = "Asc"]
-> Type : Empty or "Text" or "Number" or "Date" or "Time"or "TimeStamp" [Empty = "Text"]
* Note :
Keep empty value and double value
When you can use ValueListItem(), it's better for timing
< 2000 : 0 to 2 sec but 5000 number : between 12 and 15 secondes
Examples
Sample input
SortList ( "B¶D¶C¶¶A¶C" ; "Asc" ; "Text" )
Sample output
"¶¶A¶B¶C¶C¶D"
Function code
// SortList ( ValueList ; Sort ; Type ) v2.0
// Carrefull : Parameter is : ValueList ; Sort ; Type and not ValueList ; Type ; Sort
// If you change the name "SortList", also change in the variable $sl_Exe
/*
No dependance. Recursive CustomFunction .....
To sort a list
-> ValueList List for sort - ValueCount ( ValueList ) ≤ 100000
-> Sort : Empty or "Asc" or "Des" [Empty = "Asc"]
-> Type : Empty or "Text" or "Number" or "Date" or "Time"or "TimeStamp" [Empty = "Text"]
* Note :
Keep empty value and double value
When you can use ValueListItem(), it's better for timing
< 2000 : 0 to 2 sec but 5000 number : between 12 and 15 secondes
*/
//---------------------------------- Example
// SortList ( "B¶D¶C¶¶A¶C" ; "Asc" ; "Text" ) --> Result = "¶¶A¶B¶C¶C¶D"
//---------------------------------------------------------*/
// Agnès Barouh - August 2009 - Substitute( filemaker§tictac.fr; §; @ )
// WebSite : http://www.tictac.fr/CoinFileMaker/Page.html
//---------------------------------------------------------*/
Case (
not IsEmpty ( $$sl_V ) ;
Let ([
Size = ValueCount ( ValueList )
];
Case (
Size ≤ 2 ; Replace ( $$sl_Res ; Position ( $$sl_Res ; ¶ ; 1 ; $$sl_n ) + 1 ; 0 ; $$sl_V & ¶ ) & Let ( $$sl_V = "" ; "" ) ;
Let( [
A = Ceiling ( Size / 2 ) ;
V = GetValue ( ValueList ; A ) ;
Compare = Choose ( Type ; V ; GetAsNumber ( V ) ; GetAsDate ( V ) ; GetAsTime ( V ) ; GetAsTimestamp ( V ) ) ;
Test = Case ( Sort = "<=" ; $$sl_G <= Compare ; $$sl_G >= Compare ) ;
NewList = Choose ( Test ; Let ( $$sl_n = $$sl_n + A - 1 ; MiddleValues ( ValueList ; A ; Size )) ; LeftValues ( ValueList ; A ))
];
SortList ( NewList ; Sort ; Type )
)
));
Let ([
$sl_List = ValueList ;
$$sl_Res = GetValue ( $sl_List ; 1 ) ;
$sl_Get = "GetAs" & Case ( IsEmpty ( Type ) ; "Text" ; Type ) ;
$sl_T = Case ( Type = "Text" or IsEmpty ( Type ) ; 0 ; Type = "Number" ; 1 ; Type = "Date" ; 2 ; Type = "Time" ; 3 ; Type = "TimeStamp" ; 4 ) ;
$sl_A = Case ( Sort = "Des" ; ">=" ; Sort = "Asc" or IsEmpty ( Sort ) ; "<=" ) ;
$sl_D = Case ( Sort = "Des" ; "<=" ; ">=" ) ;
Start = 2 ; End = ValueCount ( $sl_List ) ; Diff = End - Start + 1;
End = Case ( Diff > 100000 or IsEmpty ( End ); "Error"; End );
$sl_C = Start - 1; $null = "\"\"";
Calc = Case ( Diff >= 1600; 170 ; Floor ( Diff / 10 ) + 1 );
First = Substitute ( ( 10 ^ Calc ) - 1; 9; "__________" ) ;
X = Floor ( Diff / 1700 );
$sl_Exe = Substitute ( First ; "_" ;
"Let ([
$sl_C = $sl_C + 1 ; $$sl_n = 1 ;
$$sl_V = GetValue ( $sl_List ; $sl_C );
$$sl_G = " & $sl_Get & " ( $$sl_V );
$$sl_Res = Case( $$sl_G " & $sl_A & $sl_Get & " ( GetValue ( $$sl_Res ; 1 ) ) ; $$sl_V &\¶& $$sl_Res ;
$$sl_G " & $sl_D & $sl_Get & " ( GetValue ( $$sl_Res ;$sl_C-1)) ; $$sl_Res &\¶& $$sl_V ;
SORTLIST ($$sl_Res ; $sl_A ; $sl_T))];\"\")&\¶&¶" ); // NOTA : If you change the name of the CF, "SortList", Change here too.
Final = Case ( X > 0; Substitute ( ( 10 ^ X ) - 1; 9; "Evaluate ( $sl_Exe & $null ) & " ) ) &
"Evaluate( LeftValues ( $sl_Exe ; " & Diff - ( X * 1700 ) & " ) & $null ) & " & $null
];
Case (
IsEmpty ( ValueList ) ; "" ;
End = "Error" ; "Error : Check ValueList or Start and End" ;
IsEmpty ( $sl_T ) or IsEmpty ( $sl_A ) ; "Error : Check Sort and Type" ;
Substitute ( "#^#" & Evaluate ( Final ) & "#^#"; [ "¶"; "¶#^#" ];[ "#^#¶"; "" ];[ "¶#^#"; "¶" ];[ "¶#^#"; "" ];[ "#^#"; "" ]) & $$sl_Res
)
)
& Let ([ $sl_Exe = "" ; $sl_C = "" ; $sl_List = "" ; $$sl_Res = "" ; $$sl_G = "" ; $$sl_n = "" ; $$sl_V = "" ]; "" )
)
// ===================================
/*
This function is published on FileMaker Custom Functions
to check for updates and provide feedback and bug reports
please visit http://www.fmfunctions.com/fid/260
Prototype: SortList( ValueList; Sort; Type )
Function Author: Agnès (http://www.fmfunctions.com/mid/46)
Last updated: 09 July 2010
Version: 1.3
*/
// ===================================
// SortList ( ValueList ; Sort ; Type ) v2.0__LITBR__// Carrefull : Parameter is : ValueList ; Sort ; Type and not ValueList ; Type ; Sort__LITBR__// If you change the name "SortList", also change in the variable $sl_Exe__LITBR__/*__LITBR__ No dependance. Recursive CustomFunction .....__LITBR____LITBR__ To sort a list__LITBR__-> ValueList List for sort - ValueCount ( ValueList ) ≤ 100000__LITBR__-> Sort : Empty or "Asc" or "Des" [Empty = "Asc"]__LITBR__-> Type : Empty or "Text" or "Number" or "Date" or "Time"or "TimeStamp" [Empty = "Text"]__LITBR____LITBR__* Note :__LITBR__ Keep empty value and double value__LITBR__ When you can use ValueListItem(), it's better for timing__LITBR__ < 2000 : 0 to 2 sec but 5000 number : between 12 and 15 secondes__LITBR__*/__LITBR__//---------------------------------- Example__LITBR__// SortList ( "B¶D¶C¶¶A¶C" ; "Asc" ; "Text" ) --> Result = "¶¶A¶B¶C¶C¶D"__LITBR__//---------------------------------------------------------*/__LITBR__// Agnès Barouh - August 2009 - Substitute( filemaker§tictac.fr; §; @ )__LITBR__// WebSite : http://www.tictac.fr/CoinFileMaker/Page.html__LITBR__//---------------------------------------------------------*/__LITBR____LITBR__Case (__LITBR__ not IsEmpty ( $$sl_V ) ;__LITBR____LITBR__Let ([__LITBR__ Size = ValueCount ( ValueList )__LITBR__ ];__LITBR__ Case (__LITBR__ Size ≤ 2 ; Replace ( $$sl_Res ; Position ( $$sl_Res ; ¶ ; 1 ; $$sl_n ) + 1 ; 0 ; $$sl_V & ¶ ) & Let ( $$sl_V = "" ; "" ) ;__LITBR__ Let( [__LITBR__ A = Ceiling ( Size / 2 ) ;__LITBR__ V = GetValue ( ValueList ; A ) ;__LITBR__ Compare = Choose ( Type ; V ; GetAsNumber ( V ) ; GetAsDate ( V ) ; GetAsTime ( V ) ; GetAsTimestamp ( V ) ) ;__LITBR__ Test = Case ( Sort = "<=" ; $$sl_G <= Compare ; $$sl_G >= Compare ) ;__LITBR__ NewList = Choose ( Test ; Let ( $$sl_n = $$sl_n + A - 1 ; MiddleValues ( ValueList ; A ; Size )) ; LeftValues ( ValueList ; A ))__LITBR__ ];__LITBR__ SortList ( NewList ; Sort ; Type )__LITBR__ )__LITBR__));__LITBR____LITBR__Let ([__LITBR____LITBR__ $sl_List = ValueList ;__LITBR__ $$sl_Res = GetValue ( $sl_List ; 1 ) ;__LITBR__ $sl_Get = "GetAs" & Case ( IsEmpty ( Type ) ; "Text" ; Type ) ;__LITBR__ $sl_T = Case ( Type = "Text" or IsEmpty ( Type ) ; 0 ; Type = "Number" ; 1 ; Type = "Date" ; 2 ; Type = "Time" ; 3 ; Type = "TimeStamp" ; 4 ) ;__LITBR__ $sl_A = Case ( Sort = "Des" ; ">=" ; Sort = "Asc" or IsEmpty ( Sort ) ; "<=" ) ;__LITBR__ $sl_D = Case ( Sort = "Des" ; "<=" ; ">=" ) ;__LITBR____LITBR__ Start = 2 ; End = ValueCount ( $sl_List ) ; Diff = End - Start + 1;__LITBR__ End = Case ( Diff > 100000 or IsEmpty ( End ); "Error"; End );__LITBR__ $sl_C = Start - 1; $null = "\"\"";__LITBR__ Calc = Case ( Diff >= 1600; 170 ; Floor ( Diff / 10 ) + 1 );__LITBR__ First = Substitute ( ( 10 ^ Calc ) - 1; 9; "__________" ) ; __LITBR__ X = Floor ( Diff / 1700 );__LITBR____LITBR__ $sl_Exe = Substitute ( First ; "_" ;__LITBR__"Let ([__LITBR__$sl_C = $sl_C + 1 ; $$sl_n = 1 ;__LITBR__$$sl_V = GetValue ( $sl_List ; $sl_C );__LITBR__$$sl_G = " & $sl_Get & " ( $$sl_V );__LITBR__$$sl_Res = Case( $$sl_G " & $sl_A & $sl_Get & " ( GetValue ( $$sl_Res ; 1 ) ) ; $$sl_V &\¶& $$sl_Res ;__LITBR__$$sl_G " & $sl_D & $sl_Get & " ( GetValue ( $$sl_Res ;$sl_C-1)) ; $$sl_Res &\¶& $$sl_V ;__LITBR__SORTLIST ($$sl_Res ; $sl_A ; $sl_T))];\"\")&\¶&¶" ); // NOTA : If you change the name of the CF, "SortList", Change here too.__LITBR__ __LITBR__ Final = Case ( X > 0; Substitute ( ( 10 ^ X ) - 1; 9; "Evaluate ( $sl_Exe & $null ) & " ) ) &__LITBR__ "Evaluate( LeftValues ( $sl_Exe ; " & Diff - ( X * 1700 ) & " ) & $null ) & " & $null__LITBR__ ];__LITBR__Case ( __LITBR__ IsEmpty ( ValueList ) ; "" ; __LITBR__ End = "Error" ; "Error : Check ValueList or Start and End" ;__LITBR__ IsEmpty ( $sl_T ) or IsEmpty ( $sl_A ) ; "Error : Check Sort and Type" ;__LITBR__ Substitute ( "#^#" & Evaluate ( Final ) & "#^#"; [ "¶"; "¶#^#" ];[ "#^#¶"; "" ];[ "¶#^#"; "¶" ];[ "¶#^#"; "" ];[ "#^#"; "" ]) & $$sl_Res__LITBR__ )__LITBR__)__LITBR__& Let ([ $sl_Exe = "" ; $sl_C = "" ; $sl_List = "" ; $$sl_Res = "" ; $$sl_G = "" ; $$sl_n = "" ; $$sl_V = "" ]; "" )__LITBR__)__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/260__LITBR____LITBR__ Prototype: SortList( ValueList; Sort; Type )__LITBR__ Function Author: Agnès (http://www.fmfunctions.com/mid/46)__LITBR__ Last updated: 09 July 2010__LITBR__ Version: 1.3__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.