Android Question Number range function

rleiman

Well-Known Member
Licensed User
Longtime User
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.
 
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:
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

Can get even simpler
Code: Copy
 return value>=minval and value <=maxvalue
:)
 
Upvote 0
Back
Top