SortStructuredList()

Syntax

SortStructuredList(ListName(), Options, OffsetOf(Structure\Field), Type [, Start, End])
Description
Sort the specified list, according to the given 'Options'. The list must have an associated structure. OffsetOf() can be used to retrieve the field offset in the structure associated to the list. The 'Type' parameter determine the type of the field in the structure. It must match the real structure field type. Available types are :
  #PB_Sort_Byte     : The structure field to sort is a byte (.b)
  #PB_Sort_Word     : The structure field to sort is a word (.w)
  #PB_Sort_Long     : The structure field to sort is a long (.l)
  #PB_Sort_String   : The structure field to sort is a string (.s or $)
  #PB_Sort_Float    : The structure field to sort is a float (.f)
  #PB_Sort_Double   : The structure field to sort is a double (.d)
  #PB_Sort_Quad     : The structure field to sort is a quad (.q)
  #PB_Sort_Character: The structure field to sort is a character (.c)  
An optional 'Start' and 'End' range index can be specified.

'Options' can take the following values:

0: Sort the list in ascending order (low values first)
1: Sort the list in descending order (high values first)
2: Sort a string list without case sensitive (a=A, b=B etc..) in ascending order
3: Sort a string list without case sensitive (a=A, b=B etc..) in descending order

Example:
  Structure Animal
    Name$
    Speed.l
  EndStructure
  
  NewList Animals.Animal()
  
  AddElement(Animals())
  Animals()\Name$ = "Tiger"
  Animals()\Speed = 10
  
  AddElement(Animals())
  Animals()\Name$ = "Jaguar"
  Animals()\Speed = 40
  
  AddElement(Animals())
  Animals()\Name$ = "Zebre"
  Animals()\Speed = 30
  
  ; Sort the list on the 'name$' field, which is a string
  ;
  SortStructuredList(Animals(), 0, OffsetOf(Animal\Name$), #PB_Sort_String)
  
  ForEach Animals()
    Debug Animals()\Name$+" - Speed: "+Str(Animals()\Speed)
  Next
  
  ; Sort the list on the 'speed' field, which is a long
  ;
  SortStructuredList(Animals(), 0, OffsetOf(Animal\Speed), #PB_Sort_Long)
  
  ForEach Animals()
    Debug Animals()\Name$+" - Speed: "+Str(Animals()\Speed)
  Next

Supported OS

Windows, Linux, MacOS X

<- SortStructuredArray() - Sort Index