Alaska Software Inc. - complex filter DbSetFilter( macro) doesn't work
Username: Password:
AuthorTopic: complex filter DbSetFilter( macro) doesn't work
Evert Waerdtcomplex filter DbSetFilter( macro) doesn't work
on Fri, 06 Nov 2015 17:18:36 +0100
Hi,

I am starting with Xbase++ 2.0 (from Clipper S87 what was very good with 
windows 10)

In clipper S87 this was no problem: set filter to &cFilter

How to solve this in Xbase++ 2.0? See example below dat is build up depending 
in answers from te user.

* build filter expression
cFilter:='left(CAT->rascd,1).in.getinput[1]'
if getinput[2]='E'
   cFilter:=cFilter+' .and. CAT->rascd=getinput[10]'
endif
if getinput[3]='E'
   cFilter:=cFilter+' .and. (INZ->spc1=getinput[11].or.INZ->spc2=getinput
[11].or.INZ->spc3=getinput[11].or.INZ->spc4=getinput[11])'
endif
if getinput[4]='J'
   cFilter:=cFilter+' .and. INZ->jeugd=ja'
endif
if getinput[5]='V'
   cFilter:=cFilter+' .and. CAT->koop=ja'
endif
if keus='7'
   if empty(getinput[12])
      cFilter:=cFilter+' .and. .not.empty(CAT->markcoll)'
   else
      cFilte:=cFilter+' .and. CAT->markcoll=getinput[12]'
   endif
endif
//DbSetFilter( {|| left(CAT->rascd,1).in.getinput[1] .and. INZ->jeugd=ja  } )
DbSetFilter( {|| &cFilter } )
go top


Error:
oError:args         :
          -> VALTYPE: C VALUE: left(CAT->rascd,1).in.getinput[1] .and. 
INZ->jeugd=ja
oError:canDefault   : N
oError:canRetry     : N
oError:canSubstitute: Y
oError:cargo        : NIL

The line DbSetfilter( (|| left etc. works good.
The macro doesn't

When I have to split this, it's 25 * dbsetfilter()

Solution ???
Andreas Gehrs-Pahl
Re: complex filter DbSetFilter( macro) doesn't work
on Fri, 06 Nov 2015 18:52:08 -0500
Evert,

>* build filter expression
>cFilter:='left(CAT->rascd,1).in.getinput[1]'
[...]
>//DbSetFilter( {|| left(CAT->rascd,1).in.getinput[1] .and. INZ->jeugd=ja  } )
>DbSetFilter( {|| &cFilter } )

>oError:args         :
>-> VALTYPE: C VALUE: left(CAT->rascd,1).in.getinput[1] .and. INZ->jeugd=ja

>The line DbSetfilter( (|| left etc. works good.
>The macro doesn't

Even though you didn't post the actual Xbase++ Error Codes or Error Message, 
and didn't include a small, compilable demo program that shows the actual 
error, I assume that the error is caused by the ".in." statement in your 
"cFilter" string.

I also assume that the ".in." is probably a substitute for the "$" operator, 
and will compile correctly, if pre-processed, for example when used directly 
in the DbSetFilter() function. If placed in a string, though, as you do in 
the code above, it wouldn't be pre-processed and replaced with a "$", and 
would then cause a runtime error during Macro compilation.

If the ".in." operator is actually part of the Clipper S87 syntax (and means 
what I assume it means: "Left Operand is contained in Right Operand"), then 
just replace it with the "$" operator anywhere in your code, and you should 
be fine.

So, without more information or a working demo program that shows the error, 
there isn't much (more) that any one here can do to help you.

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas.GP@Charter.net
web:   http://www.Aerospace-History.net
Thomas BraunRe: complex filter DbSetFilter( macro) doesn't work
on Tue, 10 Nov 2015 17:41:23 +0100
Andreas Gehrs-Pahl wrote:

> If the ".in." operator is actually part of the Clipper S87 syntax 

I developed several years with S87 and never came across that... looks like
a preprocessor construction.

Thomas
Evert WaerdtRe: complex filter DbSetFilter( macro) doesn't work
on Thu, 12 Nov 2015 03:11:12 +0100
More info

.in. (replacement of $ in xBase++ ) is used because it should works better in 
a codeblock for DbSetFilter
DbFilter is quit sensitive. I noticed it's better always to use an alias.  

The code:
I used almost always in S87 (and now also in the Xbase-converted code) arrays 
in my own getsystem. Only one arraynumber is active so I have full control on 
the answers of the user and I can tempory kill the active get and put a 
window on it with other gets. On closing that window the killed get will 
become active again. 

This code is used for making (a subset of) a book for shows of rabbits etc 
(in German: Kleintiershau) containing the info of the 
animals/owner/showresults)

getinput[number] is the answer of the user in @ .. say .. get
For each answer not equal to all info a special filter is needed.

My problem how do I join those filters from the several getinput[] to 1 
filterexpression for the DbSetFilter codeblock?
Andreas Gehrs-Pahl
Re: complex filter DbSetFilter( macro) doesn't work
on Tue, 17 Nov 2015 11:53:51 -0500
Evert,

>.in. (replacement of $ in xBase++ ) is used because it should works better
>in a codeblock for DbSetFilter
>DbFilter is quit sensitive. I noticed it's better always to use an alias.

I'm not sure how ".in." could work better, if it isn't even part of the 
programming language (and will be replaced with "$" by the pre-processor 
before compilation anyway).

>My problem how do I join those filters from the several getinput[] to 1 
>filterexpression for the DbSetFilter codeblock?

Your (original) code looks pretty much how I would expect it, so you already 
know how to do that. You (originally) wrote that you received a runtime 
error, which (apparently) was caused by using the ".in." statement in your 
filter clause, which (apparently) couldn't be macro-compiled at runtime.

What happens if you replace all occurrences of the ".in." statement in your 
code with the "$" operator? Do you still get a runtime error?

You never told us what the actually error was or posted any code for us to 
reproduce the error, so there really is nothing more that any of us can do 
to help you.

Hope this helps anyway,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas.GP@Charter.net
web:   http://www.Aerospace-History.net
Evert WaerdtRe: complex filter DbSetFilter( macro) doesn't work
on Fri, 25 Dec 2015 05:43:48 +0100
With thanks to Jack Duijf, Andreas and www.xbaseforum.de I solved my problem.

CFilter must be a private Var. I used a local Var.
.in. works in dBsetFilter( {|| x .in. y}) but not in a macro (strange). After 
changing this it worked with all seperate conditions.

So:
cFilter = 'x & y' etc.
bFilter = "{|| " +cFilter+ " }" 
DbSetFilter( &(bFilter) , cFilter )
Evert WaerdtRe: complex filter DbSetFilter( macro) doesn't work
on Fri, 25 Dec 2015 07:46:31 +0100
When the first cFilter := line is the ONLY selected filterexpression (with 
$ ) I needed to ad '.and. "a"="a"' otherwise no records where filtered and 
the output was empty. At first with another filterexpression of the other 
lines it did work.
This happens only in a macro not with bSetfilter( || left(CAT->rascd,1) .in. 
aInputGet[1] }).
The content of ?left(CAT->rascd,1) and ?aInputGet[1] was correct.

The complete filtercode:

cFilter := 'left(CAT->rascd,1) $ aInputGet[1] .and. "a"="a"' 
if aInputGet[2]='E'
  cFilter := cFilter+' .and. CAT->rascd = aInputGet[10]'
endif
if aInputGet[3]='E'
   cFilter := cFilter+' .and. (INZ->spc1=aInputGet[11] .or. 
INZ->spc2=aInputGet[11] .or. INZ->spc3=aInputGet[11] .or. INZ->spc4=aInputGet
[11])'
endif
if aInputGet[4]='J'
   cFilter := cFilter+' .and. INZ->jeugd = ja'
endif
if aInputGet[5]='V'
   cFilter := cFilter+' .and. CAT->koop = ja'
endif
if keus='7'
   if empty(aInputGet[12])
      cFilter := cFilter+' .and. !empty(CAT->markcoll)'
   else
      cFilter := cFilter+' .and. CAT->markcoll = aInputGet[12]'
   endif
endif
bFilter := "{|| " + cFilter + " }"
DbSetFilter( &(bFilter) , cFilter )