Subject Re: Useful functions/commands
From Ken Mayer <dbase@nospam.goldenstag.net>
Date Fri, 28 May 2021 14:41:52 -0700
Newsgroups dbase.getting-started

On 5/28/2021 1:24 PM, Ken Mayer wrote:
> On 5/28/2021 11:26 AM, Ketan G wrote:
>> Hi,
>>
>> A couple of questions.
>> Am coming to dBase 12 from Foxpro where a few functions/commands are
>> very useful. I found justify() in the dUFLP (great) so this post is
>> about the following (examples):
>>
>> 1) x = 2 ; ?between(x,1,2) will return .t.

/*
    Attempt at a function "between":
    It should probably be able to take into account any types, but
    the two types should be the same -- i.e., date compared to date,
    numeric compared to numeric, string to string ...
*/

? between( "c", "a", "z" )


function between()
    parameters compare, lowerval, upperval
    local bReturn
    bReturn = false

    // check for mismatch on types
    if type( "compare" ) # type( "lowerval" ) or;
       type( "compare" ) # type( "upperval" )
       msgbox( "Cannot compare different value types", "between Function
Error", 16 )
       return bReturn
    endif

    // make sure that lowerval is smaller than upperval:
    if lowerval => upperval
       msgbox( "The lower value parameter is not smaller than the upper
value parameter.",;
               "between Function Error", 16 )
       return bReturn
    endif

    // now a simple check:
    if ( compare > lowerval ) and ( compare < upperval )
       bReturn = true
     endif

return bReturn

Pretty simple, really. This should work for types that make sense. I am
not sure that you would want to compare logical values, for example.

Ken

--
*Ken Mayer*
Ken's dBASE Page: http://www.goldenstag.net/dbase
The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
dBASE Web Tutorial: http://www.goldenstag.net/dbase/WebTutorial/00_Menu.htm