Validate number within a range

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mirwin5
Posts: 2
Joined: Sat Feb 28, 2015 6:44 pm

Validate number within a range

Post 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
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Validate number within a range

Post by magice »

if myNumber < 8700 or myNumber > 8999
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Validate number within a range

Post 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
mirwin5
Posts: 2
Joined: Sat Feb 28, 2015 6:44 pm

Re: Validate number within a range

Post 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.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Validate number within a range

Post 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
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Validate number within a range

Post by jacque »

magice wrote:if myNumber < 8700 or myNumber > 8999
This will match all numbers. It needs to be "and" rather than "or".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Validate number within a range

Post 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.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Validate number within a range

Post 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
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Validate number within a range

Post by jacque »

Yeah, I wasn't thinking about exclusionary case. And I wasn't driving either, but I was pre-coffee.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Validate number within a range

Post 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
Post Reply