It is currently Sun Oct 25, 2020 2:54 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Extended Select
PostPosted: Fri Oct 16, 2020 7:45 pm 
Offline
User
User
User avatar

Joined: Wed Jul 15, 2020 7:10 am
Posts: 51
Hi,
would it be possible and wanted to enhance Select a bit? Coming from XProfan I can use
Code:
Select MyVar
Case 5,<0
Debug "MyVar is 5 or below 0"
Case >10
Debug "MyVar is bigger than 10"
Default
Debug "MyVar is something else"
EndSelect

to better use Select.


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 2:11 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1039
If you have a known min/max range, then you can do it with hard-coded values like below. Not exactly the formatting you want, but it works.

I take it you have some reason that you don't want to use If/ElseIf/EndIf to do what you're asking?

Code:
Select MyVar
  Case 5, -999999 To -1
    Debug "MyVar is 5 or below 0"
  Case 11 To 999999
    Debug "MyVar is bigger than 10"
  Default
    Debug "MyVar is something else"
EndSelect


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 2:17 am 
Offline
User
User
User avatar

Joined: Wed Jul 15, 2020 7:10 am
Posts: 51
Hi BarryG,
yeah that would work, if I know both boundaries. On the other hand I could set second value ridiculously high/low, this would work for most of the time too.
I want to avoid if, because I have some statements where I react to many, many values of a variable. Font know if if would fe faster though...


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 2:31 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1039
Jac de Lad wrote:
Dont know if if would be faster though

Apparently it's the same speed when you check the compiled source -> https://www.purebasic.fr/english/viewtopic.php?p=28350#p28350

But Case has one additional assembler command ("PUSH [v_a]"), so technically Case is slower than If/ElseIf/EndIf.


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 2:42 am 
Offline
User
User
User avatar

Joined: Wed Jul 15, 2020 7:10 am
Posts: 51
Ah, good to know. Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 5:24 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4980
Location: Germany
In such a case I use if
Code:
If MyVar = 5 Or MyVar < 0
  Debug "MyVar is 5 or below 0"
ElseIf MyVar > 10
  Debug "MyVar is bigger than 10"
Else
  Debug "MyVar is something else"
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 5:51 pm 
Offline
User
User
User avatar

Joined: Wed Jul 15, 2020 7:10 am
Posts: 51
Yeah of course. I just wanted to make it a bit easier with Select.


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended Select
PostPosted: Sat Oct 17, 2020 5:58 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2683
Location: Germany
Select is extended... :wink:
Code:
For a = 0 To 10
  Select a
    Case 1, 3 To 7, 9
      Debug "Case 1, 3 To 7, 9 / a = " + a
    Case 2, 8
      Debug "Case 2, 8 / a = " + a
    Default
      Debug "Default / a = " + a
  EndSelect
Next

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye