Home > Archive > Clipper > June 2004 > Filter
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| AlNofCa 2004-06-19, 3:55 am |
| I need to set a filter for a customer database. The customer.dbf has a field
for LOCATION C 2. I may need to filter for one or several customer locations
such as LOCATION == "00" .OR. LOCATION == "06". The locations needed are sent
as a parameter when the program is started. INVOICES 00,06 for example.
How can I do a SET FILTER TO for different inputs? I can create the character
string but can't figure out out to make the statement for the SET FILTER TO
???
Any suggestions?
| |
| Stephen Quinn 2004-06-19, 3:55 am |
| AlNofCa
Something like
cLoc1 := '00'
cLoc2 := '06'
cFilter := "LOCATION == [" + cLoc1 + "] .OR. LOCATION == [" + cLoc2 + "]"
--
HTH
Steve Quinn
| |
| AlNofCa 2004-06-19, 3:55 am |
| Thanks, Steve
I got that to work but now just have to figure out how to set up the string
when 1,2,3...etc locations are passed at startup.
Al
| |
| Stephen Quinn 2004-06-19, 3:55 am |
| Al
Use a function in the filter.
If the locations are passed in on the command line then store them in an array
Eg
static aLocations := {}
function main( p1,p2,p3,p4 )
if pcount() > 0
if ! empty( p1 )
aadd( aLocations, p1 )
endif
// Same for p2-4
endif
cbFilter := {|| ValidateLocation( _FIELD->LOCATION ) )
function ValidateLocation( cLocation )
return ( ascan( aLocations, cLocation ) > 0 )
--
HTH
Steve Quinn
| |
| pete@nospam.demon.co.uk 2004-06-19, 3:55 am |
| In article <20040619002429.19192.00000228@mb-m06.aol.com>
alnofca@aol.com "AlNofCa" writes:
> Thanks, Steve
> I got that to work but now just have to figure out how to set up the string
> when 1,2,3...etc locations are passed at startup.
> Al
Off the top of my head (and with caffeine deprivation) you need
to loop through that parameter. If your commandline string is
'cparam' something like
condit = "" // initial empty condition
if !empty (cparam) // i.e. param was present
cparam = cparam + ',' // adding final comma makes
// processing simpler
do while (n = AT (',', cparam)) > 0
if !empty (condit)
condit = condit + " .or. "
endif
condit = condit + "location == [" + substr (cparam, 1, n - 1) + "]"
cparam = substr (cparam, n + 1)
enddo
endif
Completely untested, but might start you off on the right track.
You'll likely want to add some error/sanity checking on those
SUBSTR()s too, add a leading zero if required etc. Then just
set filter to &condit. [does "set filter to (condit)" work?]
I'm pretty sure this will be harmless if 'condit' is still empty
after the loop (i.e. no commandline param was given) but if not
it's a simple matter to enclose the "set filter" in if/endif.
Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."
| |
| AlNofCa 2004-06-19, 8:55 pm |
| Thanks, Steve
| |
| AlNofCa 2004-06-19, 8:55 pm |
| Thanks, Pete
|
|
|
|
|