SortStructuredArray lost last value

Just starting out? Need help? Post your questions and find answers here.
kwandjeen
New User
New User
Posts: 5
Joined: Wed Apr 27, 2016 8:19 pm

SortStructuredArray lost last value

Post 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
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: SortStructuredArray lost last value

Post 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.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
kwandjeen
New User
New User
Posts: 5
Joined: Wed Apr 27, 2016 8:19 pm

Re: SortStructuredArray lost last value

Post by kwandjeen »

Funny working :shock:
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: SortStructuredArray lost last value

Post by kenmo »

kwandjeen wrote:Funny working :shock:
Agreed, it always tricks me.
Post Reply