---
url: >-
  /statelake/scripting-reference/functions-and-procedures/numeric-functions/sortintex.md
---

# SortIntEx

The **SortIntEx** procedure sorts the array of integer values **aValues**, into ascending numeric order, while maintaining the link to the paired values within the array **aOtherValues**.

For instance, where you may have an array (**a**) that holds the number of a series of cardboard cookie boxes - box 1, box 2, box 3 etc. And a linked array (**b**) that records the number of cookies contained within each of those boxes. And you want to keep this paired or linked data together so that you know that box 3 holds 56 cookies, and box 8 holds 400 cookies.

**SortIntEx** will allow you to sort the box numbers in array **a** into ascending numeric order, keeping the relationship link to array **b**.

This function only works with integers - not floating-point numbers.

Please also see the procedure [SortInt](/statelake/scripting-reference/functions-and-procedures/numeric-functions/sortint) for similar functionality.

**Declaration**: Procedure SortIntEx(var aValues : TIntegerArray; var aOtherValues : TIntegerArray)

Example with a wide range of integer values.

```pascal
procedure ScriptEvent (var Value : variant);
var
  a, b : TIntegerArray ;
  i:Integer;
begin
  SetLength(a, 11);                    //Define the length of the array 'a'
  a[0] := 37;                          //Set the 'a' array values
  a[1] := 1;
  a[2] := 56;
  a[3] := 4;
  a[4] := 107;
  a[5] := 1255;
  a[6] := 5;
  a[8] := 13;
  a[10] := 549;

  SetLength(b, 11);                   //Define the length of the array 'b'
  b[0] := 18;                         //Set the 'b' array values
  b[1] := 11;
  b[2] := 6;
  b[3] := 9874;
  b[4] := 68;
  b[5] := 2;
  b[7] := 97;
  b[8] := 6;
  b[10] := 8888;

 //Once sorted the order should be - 0, 0, 1, 4, 5, 13, 37, 56, 107, 549, 1255
 for i := Low(a) to High(a) do
 begin
    LogInfo(varToStr(i) + ':  ' + varToStr(a[i]) + ' ....  ' + varToStr(b[i]));
 end;
  LogInfo('');
  LogInfo('SORTED keeping related info together ------');
  SortIntEx(a, b);
 for i := Low(a) to High(a) do
 begin
    LogInfo(varToStr(i) + ':  ' + varToStr(a[i]) + ' ....  ' + varToStr(b[i]));
 end;

end;
```

The result of this code is shown below.
