[Implemented] Much needed change to DeleteElement()
Posted: Wed Jul 14, 2004 9:58 pm
There is a serious problem with the way DeleteElement() currently works
The output of this is:

I propose that if you delete the first element in the list, the list should then reset (in the exact same way that ResetList(mylist() works)
This would make DeleteElement() move back one element in all situations... I believe consistancy in this command is despiratly needed!
Proof of concept:
And of course the output of this is:
This means that if you want to ForEach through each element and selectivly delete them, you will run into this problem:Remove the current element from the list. After this call, the new current element is the previous element (the one before the deleted element). If that element does not exist (in other words, you deleted the first element in the list) then the new current element is the next element (the one after the deleted element). If there was only one element in the list when you deleted it then you are left with no current element!
Code: Select all
NewList mylist()
For x=1 To 5
AddElement(mylist())
mylist()=x
Next
ForEach mylist()
Debug mylist()
DeleteElement(mylist())
Next
There is no elegant way around this for us poor PB coders1
3
4
5

I propose that if you delete the first element in the list, the list should then reset (in the exact same way that ResetList(mylist() works)
This would make DeleteElement() move back one element in all situations... I believe consistancy in this command is despiratly needed!
Proof of concept:
Code: Select all
NewList mylist()
For x=1 To 5
AddElement(mylist())
mylist()=x
Next
count=0
ForEach mylist()
Debug mylist()
DeleteElement(mylist())
count=count+1
If count=1
ResetList(mylist())
count-1
EndIf
Next
1
2
3
4
5