'********************************************************************************************************** ' Name: inRange ' Author: mielk | 2014-02-10 ' ' Comment: Function to check if the given value is between two limiters defined as input ' parameters. ' Function can be used to check not only numbers but also other primitive values ' (strings, dates). ' ' ' Parameters: ' baseValue Value to be checked. ' * It can be of any primitive data type. ' * For objects and arrays function throws an error. ' low Value used as a low limiter in comparison. ' Base value must be higher or equal to this value for function to return True. ' up Value used as an up limiter in comparison. ' Base value must be lower or equal to this value for function to return True. ' ' ' Returns: ' Boolean True - if the given base value is between two limit values defined as [low] and ' [up] parameters. ' * [NOTE] Please be aware that for string comparison letter casing is important, ie. ' for limits [low] = "a" and [up] = "b" function will return True if ' [baseValue] = "ab" but False for the same value in upper case ("AB"). ' False - otherwise. ' ' ' ' Exceptions: ' IllegalTypeException Thrown if any of the given parameters is an object or an array. ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2013-04-10 mielk Function created. '********************************************************************************************************** Public Function inRange(baseValue As Variant, low As Variant, up As Variant) As Boolean Const METHOD_NAME As String = "inRange" '------------------------------------------------------------------------------------------------------ 'Comparison is not possible if any of the parameters is array or object. In such case function ------| 'moves to IllegalTypeException label. '| On Error GoTo IllegalTypeException '| If baseValue >= low Then '| If baseValue <= up Then '| inRange = True '| End If '| End If '| '----------------------------------------------------------------------------------------------------| '========================================================================================================== ExitPoint: Exit Function '---------------------------------------------------------------------------------------------------------- IllegalTypeException: 'Error handling for the case if any of the given parameters is an object or an array. GoTo ExitPoint End Function