Page 1 of 1

Validate number within a range

Posted: Mon Mar 02, 2015 11:10 pm
by mirwin5
I have searched but couldn't find how to verify an is within a certain range.
What I want to do is make sure that the number entered is within the range of 8700 to 8999.
if not I want to display a message that that is the range required.
The message box isn't a problem but I can't seem to get the syntax right to do the check.

I'm an old HyperCard guy :D just getting back in the swing of things any help would be appreciated.

Thanks

Re: Validate number within a range

Posted: Mon Mar 02, 2015 11:26 pm
by magice
if myNumber < 8700 or myNumber > 8999

Re: Validate number within a range

Posted: Mon Mar 02, 2015 11:56 pm
by dunbarx
HI.

Magice took the contrary, or rather, exclusionary case, which is just as valid. The good news is that what he proposed is identical to how you would do it the old HC way. In other words, welcome to LC. You will be glad you did.

Craig Newman

Re: Validate number within a range

Posted: Tue Mar 03, 2015 2:44 am
by mirwin5
Thanks I figured out a way to do it but this way is much more elegant I will use it when I recompile.

It is coming back. Now on to getting data from from a CSV file.

Re: Validate number within a range

Posted: Tue Mar 03, 2015 3:20 am
by dunbarx
CSV.

There are a number of threads on this. The most recent is:

http://forums.livecode.com/viewtopic.ph ... sv#p120807

Nothing particular about LC in a general discussion about CSV, but I think you should check it out.

Craig

Re: Validate number within a range

Posted: Tue Mar 03, 2015 5:16 pm
by jacque
magice wrote:if myNumber < 8700 or myNumber > 8999
This will match all numbers. It needs to be "and" rather than "or".

Re: Validate number within a range

Posted: Tue Mar 03, 2015 5:22 pm
by magice
jacque wrote:
magice wrote:if myNumber < 8700 or myNumber > 8999
This will match all numbers. It needs to be "and" rather than "or".
Look again. Actually this is correct, it is asking if it is out of the range rather than if it is within the range. I usually work this way so I can handle the "out of range" situation first and then handle the valid number with the else portion.

Re: Validate number within a range

Posted: Tue Mar 03, 2015 6:01 pm
by dunbarx
Stop, you are both wrong. :D

The OP wanted:

Code: Select all

if myNumber >= 8700 and myNumber <= 8999
I pointed out that Magice had adopted the "exclusionary" path. Well and good, if he thinks that way. This also excludes the boundaries themselves. We are not sure about that in any case.

The "or" case does not give all numbers.

Since I know both of you well, I must suggest that you stop answering these posts while driving. (Taking a cue from Klaus: :D :D :D )

Craig

Re: Validate number within a range

Posted: Tue Mar 03, 2015 6:09 pm
by jacque
Yeah, I wasn't thinking about exclusionary case. And I wasn't driving either, but I was pre-coffee.

Re: Validate number within a range

Posted: Tue Mar 03, 2015 6:19 pm
by magice
jacque wrote:Yeah, I wasn't thinking about exclusionary case. And I wasn't driving either, but I was pre-coffee.
That is usually my excuse, but since I am now 2 weeks caffeine free, my new excuse will have to be my dyslexia. :D