Hi Pat, thanks for your help,
it might be that the code is a little bit naive as I'm a VectorScript newbie and my c and java skills are a little bit rusty.
- I checked it, but I thought, it would only change the y-coordinate. In fact I have an Array Of Handles which I want to sort by Arrays Of Real. So I tried the simplest way of using a bubble sort. I just want to sort about 300 symbols in one step, so slimming down the code is not the most important thing for this moment
- 'l' is just a counter to make sure that every position in the array is checked every time. It's not the elegant but the easy way...
There might be a mistake, but I don't get it.
- could you give me an example? I tried something like that but the compiler gave back an exception.
- Neither do I. When I move the symbols to positive coordinates, the whole things works fine.
- I'm not sure what you mean ('using data structures')...
I don't have the code in a nice and structured way to present. Sorry! Here are just parts of it.
VAR
h : ARRAY [1..1000] OF Handle;
pX,pY : ARRAY [1..1000] OF Real;
biggerY: HANDLE;{used in bubble sort to store data}
i,j,k,l,m: Integer;
CountSymI : Integer;
CountSymStr : String;
havetochange,checkX: Boolean;{used in Bubblesort}
in the main program:
{to store the selected objects in Handles}
i:=1;
h:=FSActLayer;
While h<>NIL DO BEGIN
h[i+1]:=NextSObj(h);
i:=i+1;
END;
{to store the corresponding coordinates of the stored objects}
j:=1;
WHILE h[j] <> NIL DO BEGIN
Get2DPt(h[j],1,pX[j],pY[j]);
j:=j+1;
END;
{bubble sort}
FOR l:=1 TO i-1 DO Begin
FOR k:=1 TO i-1 DO Begin
checkX:=FALSE;
havetochange:=FALSE;
Get2DPt(h[k],1,pX[k],pY[k]);
Get2DPt(h[k+1],1,pX[k+1],pY[k+1]);
IF (pY[k]
IF (pY[k]=pY[k+1]) THEN checkX:=TRUE;
IF (havetochange=TRUE) THEN biggerY:=h[k]; {ein simpler swap algorithmus}
IF (havetochange=TRUE) THEN h[k]:=h[k+1];
IF (havetochange=TRUE) THEN h[k+1]:=biggerY;
IF(checkX=TRUE)&(pX[k]>pX[k+1]) THEN biggerY:=h[k];
IF(checkX=TRUE)&(pX[k]>pX[k+1]) THEN h[k]:=h[k+1];
IF(checkX=TRUE)&(pX[k]>pX[k+1]) THEN h[k+1]:=biggerY;
END;
END;
{writing the new handle number into the data base}
CountsymI:=1;
While h[CountsymI]<>NIL DO BEGIN
CountSymStr:=NUM2Str(0,CountSymI);SetRField(h[CountsymI],'RechteckigeDB','Pultnr',CountSymStr); {changes the field 'pultnr' in the database 'RechteckigeDB'}
CountSymI:=CountSymI+1;
END;
then of course END and RUN...
I hope that you will understand the way I want it to work;-)