It is currently Fri Nov 15, 2019 2:35 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Select/Case with ranges
PostPosted: Tue Feb 05, 2013 2:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 498
Location: Doubs - France
Personally, I think it's a bug but may be Fred not :?:

Ranges for checking value could be with positive/negative step like for to next loop.
but if range is with a negative step, result of check will be wrong with select/case (unable to put step-1).
just take a look to the following code
result will be case 8, but what about case 6 ? For me, case 6 is a correct range.

if you know the range, you could put correct values but if range is defined with variables (etc.), you must first check values to put correct "case range" because of possible wrong result due to compiler. Documentation tell us:
Case <expression> [, <expression> [<numeric expression> To <numeric expression>]]
So, ranges could be a complex expression.
That's why i I think it's a bug.

Fred, if you don't think so, documentation must be updated with explanations about ranges, wich is not currently the case.

Code:
a.i = -922

Select a
      Case   1  To  92233720368547758
        Debug "case 5  " + Str(a)
       
      Case  -1 To  -92233720368547758
        Debug "case 6  " + Str(a)
       
      Case  0  To  9223372036854775807
        Debug "case 7  " + Str(a)
       
      Case  -92233720368547758  To  0
            Debug "case 8  " + Str(a)
EndSelect

_________________
A+
Denis


Top
 Profile  
Reply with quote  
 Post subject: Re: Select/Case with ranges
PostPosted: Tue Feb 05, 2013 3:41 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3700
Location: Berlin, Germany
I think it's common sense to write the lower value first, and then to write the higher value after "To". E.g. would you expect me to say "I lived in City X from 2005 to 2010." or rather "I lived in City X from 2010 to 2005." ? :-) I do not see a bug here, neither in the compiler nor in the documentation.

Denis wrote:
but if range is defined with variables (etc.), you must first check values to put correct "case range"

That's no problem. If you don't know beforehand which bound the lower one is, just check both cases:
Code:
a = 10
b =  1
value = 5

Select value
   Case a To b, b To a
      Debug "Found!"
EndSelect

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Select/Case with ranges
PostPosted: Tue Feb 05, 2013 4:31 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 498
Location: Doubs - France
You're right Little John, the solution is Ok

but i still thinking that both ranges must be correctly interpreted by compiler.
Tks

_________________
A+
Denis


Top
 Profile  
Reply with quote  
 Post subject: Re: Select/Case with ranges
PostPosted: Tue Feb 05, 2013 5:46 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3115
Location: Boston, MA
Call me confused. :?
Why would the order of case statements require pre-knowledge of the ranges?
On PB v5 this code does not work with quads.
Maybe this is fixed with v5.1bx?

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 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