viernes, septiembre 01, 2006

Ordenar un array

Codigo C/AL para ordenar un array.

OnRun()
myText[1] := 'Z8754';
myText[2] := 'M2532';
myText[3] := 'D1992';
myText[4] := 'A9900';

SortArrayOfText(myText);

FOR i := 1 TO ARRAYLEN(myText) DO BEGIN
 IF myText[i] <> '' THEN
  MESSAGE(myText[i]);
END;


SortArrayOfText(VAR ParamArray : ARRAY [999] OF Text[30])
COMPRESSARRAY(ParamArray);
FOR i := 1 TO ARRAYLEN(ParamArray) DO BEGIN
 IF ParamArray[i] = '' THEN
  Finish := i;
END;

REPEAT
 ToExit := TRUE;
 FOR i := 1 TO (Finish - 1) DO BEGIN
  IF ParamArray[i] > ParamArray[i + 1] THEN BEGIN
   Swap(ParamArray[i], ParamArray[i + 1]);
   ToExit := FALSE;
  END;
 END;
 Finish -= 1;
UNTIL ToExit;


Swap(VAR Param1 : Text[30];VAR Param2 : Text[30])
temp := Param2;
Param2 := Param1;
Param1 := temp;

No hay comentarios:

Publicar un comentario