Bug SelectElement()

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

Bug SelectElement()

Post by Splunk »

Hi guys,

there is something wrong with SelectElement() or AddElement().

Code: Select all

NewList void.l()

For a = 1 To 5
   AddElement(void())			
   void()=a
Next

ForEach void()
   Debug void()
Next
Result: ok, absolutly correct
1
2
3
4
5

And now the Bug:
-----------------------

Code: Select all

NewList void.l()

For a = 1 To 5
   SelectElement(void(), 0)        ; the newest value should be at the front of the list(!)
   AddElement(void())
   void()=a
Next

ForEach void()
   Debug void()
Next
Result: ????
1
5
4
3
2

Correct to expect would be:
5
4
3
2
1

// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
// Added code tags (Kiffi)
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Bug SelectElement()

Post by Little John »

You can't select the first element (= position 0) of an empty list.

This seems to be what you want to do:

Code: Select all

NewList void()

For a = 1 To 5
   ResetList(void())
   AddElement(void())
   void() = a
Next

ForEach void()
   Debug void()
Next

PS: When writing a bug report, it makes sense to mention the PB version that was used for testing.
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Bug SelectElement()

Post by IceSoft »

replace SelectElement/AddElement with InsertElement and it works
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

Re: Bug SelectElement()

Post by Splunk »

Ok, not a bug, a thinking error of mine.

Thanks! :oops:
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Bug SelectElement()

Post by mestnyi »

Interesting. :)

Code: Select all

NewList void.l()
count = 50000000

time = ElapsedMilliseconds()
For a = 1 To count
  InsertElement(void())
  void()=a
Next
Debug " - "+Str(ElapsedMilliseconds()-time) ;  result - 9659

Debug "     ---    "
ClearList(void())

time = ElapsedMilliseconds()
For a = 1 To count
  ResetList(void())
  AddElement(void())
  void() = a
Next
Debug " - "+Str(ElapsedMilliseconds()-time) ; result - 11339
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Bug SelectElement()

Post by NicTheQuick »

mestnyi wrote: Thu Feb 02, 2023 4:41 pm Interesting. :)
As long as you are using the Debugger there is nothing interesting about that. But even without the the debugger it should be clear that it is slower to have two function calls instead of just one.

Edith:
Here are the differences on my system with and without debugger:
With debugger:
- 3142
---
- 4243


Without debugger:
- 591
---
- 624
And the code:

Code: Select all

NewList void.l()
count = 50000000

OpenConsole()

time = ElapsedMilliseconds()
For a = 1 To count
	InsertElement(void())
	void()=a
Next
time = ElapsedMilliseconds() - time
PrintN(" - " + time)

PrintN("     ---    ")
ClearList(void())

time = ElapsedMilliseconds()
For a = 1 To count
	ResetList(void())
	AddElement(void())
	void() = a
Next
time = ElapsedMilliseconds() - time
PrintN(" - " + time)
Input()

CloseConsole()
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Bug SelectElement()

Post by mestnyi »

Your example does nothing on Macos.
Yes, you are right that two calls will be slower. :)
I was wondering what else works.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Bug SelectElement()

Post by NicTheQuick »

mestnyi wrote: Thu Feb 02, 2023 7:44 pm Your example does nothing on Macos.
Yes, you are right that two calls will be slower. :)
I was wondering what else works.
If you are on Mac or Linux you need to set the executable format to "Console" in the compiler options. Otherwise the console window does not show up.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Bug SelectElement()

Post by mestnyi »

NicTheQuick wrote: Thu Feb 02, 2023 8:10 pm
mestnyi wrote: Thu Feb 02, 2023 7:44 pm Your example does nothing on Macos.
Yes, you are right that two calls will be slower. :)
I was wondering what else works.
If you are on Mac or Linux you need to set the executable format to "Console" in the compiler options. Otherwise the console window does not show up.
I did not know it.
how this other behavior hurts me. :cry:
or rather, how to do it, I did not find in the settings. :oops:
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bug SelectElement()

Post by mk-soft »

mestnyi wrote: Fri Feb 03, 2023 6:53 am
NicTheQuick wrote: Thu Feb 02, 2023 8:10 pm
mestnyi wrote: Thu Feb 02, 2023 7:44 pm Your example does nothing on Macos.
Yes, you are right that two calls will be slower. :)
I was wondering what else works.
If you are on Mac or Linux you need to set the executable format to "Console" in the compiler options. Otherwise the console window does not show up.
I did not know it.
how this other behavior hurts me. :cry:
or rather, how to do it, I did not find in the settings. :oops:
Under Compiler options, where you also set whether it is a Window APP or a DLL,SO,DyLib
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
Post Reply