Found an issue in SpiderBasic ? Please report it here !
User avatar
Peter
 
Posts: 689
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

MoveElement() does not work as expected

by Peter Sun Feb 16, 2020 6:23 pm

Hello,

MoveElement() does not work as expected.

Code from Help:
Code: Select all
NewList Numbers()

For k=0 To 10
  AddElement(Numbers())
  Numbers() = k
Next

SelectElement(Numbers(), 5)
*Relative = @Numbers()                             ; get address of element 5

SelectElement(Numbers(), 0)
MoveElement(Numbers(), #PB_List_After, *Relative)  ; move after element 5

SelectElement(Numbers(), 10)
MoveElement(Numbers(), #PB_List_First)             ; move to the beginning

; Result
;
ForEach Numbers()
  Debug Numbers()
Next


SpiderBasic-Output:
10
1
2
3
4
5
6
7
8
9


PureBasic-Output:
10
1
2
3
4
5
0
6
7
8
9
Sirius-2337
 
Posts: 35
Joined: Wed Mar 26, 2014 5:47 pm

Re: MoveElement() does not work as expected

by Sirius-2337 Mon Feb 17, 2020 2:57 pm

The problem is not MoveElement, but that "@Numbers()" returns the value of the list element instead of a pointer to it.

Following code works as expected.
Code: Select all
NewList Numbers()

For k=0 To 10
  AddElement(Numbers())
  Numbers() = k
Next

*Relative = SelectElement(Numbers(), 5)            ; get address of element 5

SelectElement(Numbers(), 0)
MoveElement(Numbers(), #PB_List_After, *Relative)  ; move after element 5

SelectElement(Numbers(), 10)
MoveElement(Numbers(), #PB_List_First)             ; move to the beginning

; Result
;
ForEach Numbers()
  Debug Numbers()
Next


So it seems the @-operator does not work.
Return to Bugs Reports

Who is online

Users browsing this forum: No registered users and 1 guest