rleiman Well-Known Member Licensed User Longtime User Jan 3, 2014 #1 Hi Everyone, Is there a function in B4A that you can pass in a number and the function returns true if the number is within a range? Example: Code: Copy Sub fcnNumberInRange (intNumberIn as Int, intRangeStarting as Int, intRangeEnding as Int) As Boolean ' Code to determine if the passed in number is within the range. If the number is in the range then return true else return false end if End Sub Usage like testing if 55 is in between 20 and 100: Code: Copy If fcnNumberInRange (55, 20, 100) then ' Do something here. End If I plan to use this in a Case Select structure.
Hi Everyone, Is there a function in B4A that you can pass in a number and the function returns true if the number is within a range? Example: Code: Copy Sub fcnNumberInRange (intNumberIn as Int, intRangeStarting as Int, intRangeEnding as Int) As Boolean ' Code to determine if the passed in number is within the range. If the number is in the range then return true else return false end if End Sub Usage like testing if 55 is in between 20 and 100: Code: Copy If fcnNumberInRange (55, 20, 100) then ' Do something here. End If I plan to use this in a Case Select structure.
DonManfred Expert Licensed User Longtime User Jan 3, 2014 #2 I dont know such sub. But why dont you write your own? It should be easy to do. Code: Copy sub fcnNumberInRange (value as double, minval as double, maxval as double ) if value >= minval then if value <= maxval then return true else return false end if else return false end if end sub Last edited: Jan 3, 2014 Upvote 0
I dont know such sub. But why dont you write your own? It should be easy to do. Code: Copy sub fcnNumberInRange (value as double, minval as double, maxval as double ) if value >= minval then if value <= maxval then return true else return false end if else return false end if end sub
mc73 Well-Known Member Licensed User Longtime User Jan 3, 2014 #3 DonManfred said: I dont know such sub. But why dont you write your own? It should be easy to do. Code: Copy sub fcnNumberInRange (value as double, minval as double, maxval as double ) if value >= minval then if value <= maxval then return true else return false end if else return false end if end sub Click to expand... Can get even simpler Code: Copy return value>=minval and value <=maxvalue Upvote 0
DonManfred said: I dont know such sub. But why dont you write your own? It should be easy to do. Code: Copy sub fcnNumberInRange (value as double, minval as double, maxval as double ) if value >= minval then if value <= maxval then return true else return false end if else return false end if end sub Click to expand... Can get even simpler Code: Copy return value>=minval and value <=maxvalue