Page 1 of 1

[4.41] Bug in ArraySort (solved)

Posted: Thu Mar 18, 2010 8:46 pm
by neotoma
I found a very annoying Bug in PB4.41 as i used the SortArray-Function.
It allways add a Zero Entry and loose the highest one.

Example:

Code: Select all

;PB 4.41-Bug

RandomSeed( ElapsedMilliseconds() )

#ITEMS=6

;Fill Array With Random Values:
Dim idx.i(#ITEMS)
For i = 1 To #ITEMS
  idx(i-1) = i*10; Random(10000)
Next

Debug "Before Sorting:"
Debug "---------------"
;Print Result
For i = 0 To #ITEMS-1
  Debug( Str( idx(i) ) )
Next

;Sort
SortArray(idx(),#PB_Sort_Ascending)

Debug "After Sorting:"
Debug "---------------"
;Print Result
For i = 0 To #ITEMS-1
  Debug( Str( idx(i) ) )
Next


;With Sort we loose the highest number, and get a zero as lowest 
;Also if ther are no zero value in the array.
Mike

Re: [4.41] Bug in ArraySort

Posted: Thu Mar 18, 2010 8:52 pm
by Arctic Fox
Well, you have seven items in the array, the last one is zero.

Try this and you will find out

Code: Select all

Debug "After Sorting:"
Debug "---------------"
;Print Result
For i = 0 To #ITEMS
  Debug( Str( idx(i) ) )
Next

Re: [4.41] Bug in ArraySort

Posted: Thu Mar 18, 2010 9:34 pm
by IdeasVacuum
...just replace "#ITEMS - 1" with "#ITEMS" in both loops. Your code seems to be attempting to avoid collecting the value of the first index (index zero). If there is a good reason to do that, then this is how:

Code: Select all

#ITEMS=6

;Fill Array With Random Values:
Dim idx.i(#ITEMS)
For i = 1 To #ITEMS
  idx(i) = i*10
Next

Debug "Before Sorting:"
Debug "---------------"
;Print Result
For i = 1 To #ITEMS
  Debug( Str( idx(i) ) )
Next

;Sort
SortArray(idx(),#PB_Sort_Ascending)

Debug "After Sorting:"
Debug "---------------"
;Print Result
For i = 1 To #ITEMS
  Debug( Str( idx(i) ) )
Next

Re: [4.41] Bug in ArraySort

Posted: Thu Mar 18, 2010 9:38 pm
by neotoma
Yes, you are right - was my fault.

Thanks