SortList()...Bug?

Just starting out? Need help? Post your questions and find answers here.
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

SortList()...Bug?

Post by Splunk »

Hi guys,

before I post something in the bug forum again and it's not a bug after all, I'll ask here first if I'm too stupid again.

Code: Select all

Global NewList x.s()

AddElement(x()): x()="e"
AddElement(x()): x()="d"
AddElement(x()): x()="c"
AddElement(x()): x()="b"
AddElement(x()): x()="a"

SortList(x(), #PB_Sort_Ascending)

ForEach x()
	Debug x()
Next
Result:
a
b
c
d
e

Perfect! :D


However, with the start and end parameters specified, nothing is sorted at all:

Code: Select all

Global NewList x.s()

AddElement(x()): x()="e"
AddElement(x()): x()="d"
AddElement(x()): x()="c"
AddElement(x()): x()="b"
AddElement(x()): x()="a"

SortList(x(), #PB_Sort_Ascending, 3, 5)

ForEach x()
	Debug x()
Next
Result:
e
d
c
b
a

??? :cry:

What am I doing wrong now? (PB 5.41)
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: SortList()...Bug?

Post by Fred »

Your last index is wrong as you have 5 elements, it's from 0 to 4:

Code: Select all

Global NewList x.s()

AddElement(x()): x()="e"
AddElement(x()): x()="d"
AddElement(x()): x()="c"
AddElement(x()): x()="b"
AddElement(x()): x()="a"

SortList(x(), #PB_Sort_Ascending, 2, 4)

ForEach x()
	Debug x()
Next
I agree it's probably missing a runtime check though
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: SortList()...Bug?

Post by mk-soft »

First element is Zero (0)

Code: Select all

Global NewList x.s()

AddElement(x()): x()="e"
AddElement(x()): x()="d"
AddElement(x()): x()="c"
AddElement(x()): x()="b"
AddElement(x()): x()="a"

SortList(x(), #PB_Sort_Ascending, 2, 4)

ForEach x()
	Debug x()
Next
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

Re: SortList()...Bug?

Post by Splunk »

Yes, in the original code as end parameter I used "Listsize()". This is then of course wrong! Thanks!
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: SortList()...Bug?

Post by Fred »

Added runtime check
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

Re: SortList()...Bug?

Post by Splunk »

Fred wrote: Sun Feb 05, 2023 4:12 pmAdded runtime check
It doesn't get any faster than this! Great! :D :D
Post Reply