Listbox Filter on Logical Field

Post Reply
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Listbox Filter on Logical Field

Post 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
User avatar
tnhoe
Posts: 83
Joined: Tue Nov 08, 2005 11:09 am
Location: Malaysia
Contact:

Post by tnhoe »

convert field type to string when indexing :-

index on transform(template,'@!')+custno
Regards

Hoe, email: easywin3@yahoo.com
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Post by Greg Gammon »

using the SELECT transform(field->template, "@!") FOR "T" works perfectly (of course).
Thanks again!
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Post 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
User avatar
tnhoe
Posts: 83
Joined: Tue Nov 08, 2005 11:09 am
Location: Malaysia
Contact:

Post by tnhoe »

is oCustno an object or a string ? it must be a string value
Regards

Hoe, email: easywin3@yahoo.com
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Post 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
User avatar
tnhoe
Posts: 83
Joined: Tue Nov 08, 2005 11:09 am
Location: Malaysia
Contact:

Post 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
Regards

Hoe, email: easywin3@yahoo.com
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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).
Post Reply