Is there a way to determine whether a number is within
a specified range other than writing
if theVar is > .... then
if theVar is < ... then ?
Number between .....
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Number between .....
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 256
- Joined: Sun May 27, 2007 8:19 pm
Re: Number between .....
You could have the two conditions in one line using and like this
Martin
Code: Select all
if tVar > 10 and tVar < 20 then
-- do something
end if
Re: Number between .....
Or, cuter, (from the dictionary)
max(lowValue,min(myValue,highValue))
Though this gives a different sort of answer.
Craig Newman
max(lowValue,min(myValue,highValue))
Though this gives a different sort of answer.
Craig Newman
-
- Posts: 58
- Joined: Mon Oct 28, 2013 1:23 pm
Re: Number between .....
If you need the comparison more than once in your code, it is better to create a custom handler 
numberWithin(2,2,4) --> true
numberWithin(5,2,4) --> false
Happy Coding
Torsten

numberWithin(2,2,4) --> true
numberWithin(5,2,4) --> false
Code: Select all
function numberWithin pNumber, pMin, pMax
if pNumber >= pMin and pNumber <= pMax then
return true
else
return false
end if
end numberWithin
Torsten
Re: Number between .....
A little late for the party, Torsten... 
