Page 1 of 1

Number between .....

Posted: Wed Dec 02, 2015 9:59 pm
by RossG
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 ?

Re: Number between .....

Posted: Wed Dec 02, 2015 10:12 pm
by Martin Koob
You could have the two conditions in one line using and like this

Code: Select all

 if tVar > 10 and tVar < 20 then 
-- do something
end if
Martin

Re: Number between .....

Posted: Wed Dec 02, 2015 10:48 pm
by dunbarx
Or, cuter, (from the dictionary)

max(lowValue,min(myValue,highValue))

Though this gives a different sort of answer.

Craig Newman

Re: Number between .....

Posted: Sat Nov 07, 2020 11:23 am
by TorstenHolmer
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

Code: Select all

function numberWithin pNumber, pMin, pMax
   
   if pNumber >= pMin and pNumber <= pMax then
      return true
   else
      return false
   end if
   
end numberWithin

Happy Coding
Torsten

Re: Number between .....

Posted: Sat Nov 07, 2020 11:55 am
by Klaus
A little late for the party, Torsten... :D