Page 1 of 1

SortStructuredArray lost last value

Posted: Tue May 23, 2017 6:57 am
by kwandjeen
I get the impression that the SortStructuredArray command is bugged. After I throw it I lose the last value that goes to 0.
Do I make a mistake or is it a bug?
Cordially.

Code: Select all

Structure _tab
  position.i
  valeur.i
EndStructure

Global Dim MonTableau._tab(5)
For i=0 To ArraySize(MonTableau())-1
  MonTableau(i)\position = i+1
  MonTableau(i)\valeur = i+1
Next i

Debug "***********"
Debug ArraySize(MonTableau())
Debug "***********"
For k = 0 To ArraySize(MonTableau())-1
  Debug MonTableau(k)\valeur
Next

SortStructuredArray(MonTableau(), #PB_Sort_Ascending, OffsetOf(_tab\position), TypeOf(_tab\position))
Debug "***********"
For k = 0 To ArraySize(MonTableau())-1
  Debug MonTableau(k)\valeur
Next

Re: SortStructuredArray lost last value

Posted: Tue May 23, 2017 8:14 am
by c4s
ArraySize() is misleading as Dim array(5) actually creates an array with 6 elements ("0" included). So simply remove all "-1" and you'll see that SortStructuredArray() works as expected.

Re: SortStructuredArray lost last value

Posted: Wed May 24, 2017 6:27 am
by kwandjeen
Funny working :shock:

Re: SortStructuredArray lost last value

Posted: Wed May 24, 2017 12:24 pm
by kenmo
kwandjeen wrote:Funny working :shock:
Agreed, it always tricks me.