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:

B4X:
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:

B4X:
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
I dont know such sub. But why dont you write your own?
It should be easy to do.

B4X:
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

mc73

Well-Known Member
Licensed User
Longtime User
I dont know such sub. But why dont you write your own?
It should be easy to do.

B4X:
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
B4X:
 return value>=minval and value <=maxvalue
:)
 
Upvote 0
Top