| Subject |
Re: Useful functions/commands |
| From |
Ken Mayer <dbase@nospam.goldenstag.net> |
| Date |
Fri, 28 May 2021 14:56:49 -0700 |
| Newsgroups |
dbase.getting-started |
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.
>
> 2) x = 'a' ; ?inlist(x,'b','c','d') will return .f.
The example above would require needing to check for an unknown number
of parameters, which could be done, but it's easier to do something like
here.
/*
Attempt at a function "inlist":
First value is checked against second, which can be a string, or
an array ... providing a set of parameters gets weird ... easier to
keep it to two.
Usage:
? inlist( "c", "a, b, d, g, f" ) // return false
? inlist( "c", "a, b, c, d, e" ) // return true
? inlist( "c", {"a", "b", "c", "d", "e" } ) // return true
a = new array()
a.add( "a" )
a.add( "b" )
a.add( "c" )
? inlist( "c", a ) // return true
*/
clear
? "Look in a string: " + inlist( "c", "a, b, d, e, g, f" )
? "Look in array 1: " + inlist( "c", { "a", "b", "c", "e", "g", "f"} )
a = new array()
a.add( "a" )
a.add( "b" )
//a.add( "c" )
a.add( "d" )
a.add( "d" )
a.add( "f" )
a.add( "g" )
? "Look in array 2: " + inlist( "c", a )
function inlist()
parameters compare, list
local bReturn
bReturn = false
// check pCount()
if pCount() < 2 or pCount() > 2
msgbox( "There should be two parameters for this function!",;
"inlist Function Error", 16 )
return bReturn
endif
// check for mismatch on types
if type( "compare" ) # "C"
msgbox( "First parameter must be character", "between Function
Error", 16 )
return bReturn
endif
if type( "list" ) # "C" and ;
type( "list" ) # "A"
msgbox( "The lower value parameter is not smaller than the upper
value parameter.",;
"between Function Error", 16 )
return bReturn
endif
// this gets processed differently depending on whether
// the list is a character string or an array:
if type( "list" ) == "C"
// character:
if list.indexOf( compare ) > 0
bReturn = true
endif
else
// the list is an array:
if list.scan( compare ) > 0
bReturn = true
endif
endif
return bReturn
--
*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
|
|