Page 1 of 1
Listbox Filter on Logical Field
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Jun 27, 2006 6:32 pm
by Greg Gammon
Greetings....
I have a Listbox that I want to show only items that are .t. for a logical field (field->template) in some views and all the data in another view.
Using the Set Filter command works but is slow. Ive tried to set up an Index on that logical field but am getting an index error.
INDEX ON field->template + field->custno where template is logical and custno is character. Can you do an Index on a logical field? Or is there a better way to accomplish what I am trying to do?
I would then use the SET SCOPE or SELECT function for the Listbox. Any guidance on this is appreciated!
Greg
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Jun 27, 2006 7:25 pm
by tnhoe
convert field type to string when indexing :-
index on transform(template,'@!')+custno
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Jun 27, 2006 8:13 pm
by Greg Gammon
Ok, that fixes the Index problem fine...thanks!
Next issue is the Listbox.
I use:
REDEFINE LISTBOX oLbx ..... SELECT estmain->template FOR .t. ;
In runtime, I get this ALERT message:
TWBrowse SetFilter() types don't match with current Index type.
You click OK on this Alert and the Listbox pops up and displays perfectly.
Other ideas? (or how to disable that Alert message?)
Thanks!
Greg
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Jun 27, 2006 9:19 pm
by Antonio Linares
Greg,
transform(template,'@!')+custno is not a logical value.
You may use:
... SELECT transform(template,'@!')+custno FOR ...
Anyhow, you may modify source\classes\wbrowse.prg and comment out the MsgAlert() call.
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Jun 27, 2006 9:53 pm
by Greg Gammon
using the SELECT transform(field->template, "@!") FOR "T" works perfectly (of course).
Thanks again!
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Jun 30, 2006 2:24 pm
by Greg Gammon
Have another issue with this...
My index is INDEX ON transform(field->logical, '@!')+field->custno
Is it possible to set scope or use the Listbox...Select/For command using both Index keys?
For instance...Set Scope To "T"+oCustno ? I can't seem to make anything work in this regard.
Thanks,
Greg
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Jun 30, 2006 4:03 pm
by tnhoe
is oCustno an object or a string ? it must be a string value
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Jun 30, 2006 5:07 pm
by Greg Gammon
yes oCustno is a string value...i should have represented that differently in my example.
What i have tried is this:
cCustno := "string"
SET ORDER TO "T"+cCustno
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sat Jul 01, 2006 5:19 am
by tnhoe
index on transform(template,'@!')+custno tag tempcust to yourcdx
set order to tag tempcust
redefine listbox oLbx ... ;
select transform(template,'@!')+custno for "T"+cCustno
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sat Jul 01, 2006 1:49 pm
by Greg Gammon
That is exactly what I did do and it doesn't seem to work. Can't understand why but I'll keep plugging away at it. Thanks again.
G
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sat Jul 01, 2006 3:42 pm
by James Bott
Why not use scopes?
(cAlias)->ordScope(0,"T"+cCustno)
(cAlias)->ordScope(1,"T"+cCustno)
Note that cCustno needs to be exactly the same length as the CUSTNO field.
James
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sat Jul 01, 2006 11:42 pm
by Greg Gammon
ahhhh.....I did try ordscope but didn't take into account the exact length for cCustno.
Im not sure I exactly grasp the numerical indicator in the ordscope(0,...)
I tried using a 1 not sure what I was doing, so any explanation is helpful...the help files I read did not compute...laugh
I also did Ordscope(1, cAlias->...) Didn't think about the alias being outside ordscope. Why is that?
thanks!
G
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Jul 02, 2006 5:40 pm
by James Bott
Greg,
Zero is the top scope--think of it as <=. One is the top scope, think of it as >=.
The alias here is not referring to the scope value (cCustno), but the scope function.
For safe programming force the var, cCustno, to be the length of the field:
cCustno:= padr(cCustno, len(field->custno))
This way if you ever change the length of the field it won't break your code.
James
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Jul 02, 2006 6:30 pm
by James Bott
I noticed that I made a syntax mistake, ordScope should be surrounded with parentheses like this:
(cAlias)->(ordScope(0,"T"+cCustno))
(cAlias)->(ordScope(1,"T"+cCustno))
You might also want to consider using database objects which frees you from using aliases and also provides lots of other benefits. There are a couple of articles about this on my website (see link button below).