Page 1 of 1

Using ListBox

Posted: Thu Sep 18, 2008 11:50 am
by yardenmo
Hi,

I'm trying to use ListBox, to show just those fields matching a predefined
condition, like:
"MasLoad->Manifest == cManifest .and. MasLoad->TalyFlag"

where Manifest is C
and TalyFlag is L

I was trying: SELECT <cField> FOR <uValue1> [ TO <uValue2>]

But I'm doing something wrong.

*. Is there a way to use something like AChoice()?
*. Is there a picklist that does an incremental search as letters are entered?


Thanks,
Moshe Yarden

Posted: Thu Sep 18, 2008 11:55 am
by Antonio Linares
Moshe,

> *. Is there a picklist that does an incremental search as letters are entered?

You have a working examples in FWPPC\samples\TestBrwS.prg :-)

Posted: Thu Sep 18, 2008 11:57 am
by Antonio Linares
Moshe,

> I was trying: SELECT <cField> FOR <uValue1> [ TO <uValue2>]

In order to use that clause, you need to have an index built with the expression to be searched.

Alternatively you can use OrdScope() to set a top and bottom range in the database. Please do a search in these forums for "OrdScope", thanks

Posted: Thu Sep 18, 2008 12:00 pm
by Antonio Linares
Here you have an example:

Code: Select all

   DbSelectArea( "bp" ) 
   bp->( OrdSetFocus( "bpopen" ) )  // it's a conditional index created with FOR ...

   bp->( ordScope( 0, topValue ) ) 
   bp->( ordScope( 1, bottomValue ) ) 

Posted: Thu Sep 18, 2008 1:09 pm
by yardenmo
Antonio,

Thanks.

I'll try it.

in: SELECT <cField> FOR <uValue1> [ TO <uValue2>]

How do I write cField? is it the name of the field or in " "
and, the uValue1 - is it an expression the returns true / false?


Moshe Yarden

Posted: Thu Sep 18, 2008 1:12 pm
by yardenmo
Antonio,

Does the Combo Box enables incremental search as well?


Thanks,
Moshe Yarden

Posted: Thu Sep 18, 2008 4:37 pm
by Antonio Linares
Moshe,

> Does the Combo Box enables incremental search as well?

We have a version that does it, but some users are reporting some problems with it.

Better do it the way we do it in samples\TestBrwS.prg

Posted: Thu Sep 18, 2008 4:39 pm
by Antonio Linares
Moshe,

Regarding the SELECT clause here you have an example from FWH:

Code: Select all

   @ 1, 1 LISTBOX oLbx FIELDS aHBitmaps[ Max( 1, Clientes->Nivel ) ],;
                              Clientes->Nombre, Clientes->Direccion,;
                              Clientes->Telefono, ;
                              Str( Clientes->Edad, 3 ) ;
          HEADERS    "Lev.", "Name", "Address", "Phone", "Age" ;
          FIELDSIZES 34, 240, 310, 114, 24 ;
          SELECT Nombre FOR "Laureano" TO "Paco" ;
          SIZE 284, 137 OF oDlg
Nombre is a field name. "Laureano" is the top value and "Paco" is the bottom value. The index has to use Nombre as the key.

Posted: Thu Sep 18, 2008 5:29 pm
by yardenmo
Antonio,

Thanks. It is very helpful.

Is there a way to show a table (like in ListBox) but the items are taken from an array. That way I can fill the array with itmes (dbf records), passing any kind of restrictions, without the need to have many indexes?



Moshe Yarden

Posted: Thu Sep 18, 2008 5:35 pm
by Enrico Maria Giordano

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oBrw

    LOCAL aArray := { { "Test1_1", "Test1_2" },;
                      { "Test2_1", "Test2_2" },;
                      { "Test3_1", "Test3_2" } }

    LOCAL nCur := 1

    DEFINE DIALOG oDlg;
           TITLE "Browsing array";
           SIZE 800, 600

    @ 0, 0 LISTBOX oBrw FIELDS IF( EMPTY( aArray ), "", aArray[ nCur, 1 ] ),;
                               IF( EMPTY( aArray ), "", aArray[ nCur, 2 ] );
           SIZE 200, 200;
           HEADERS "Test1", "Test2"

    oBrw:bLogicLen = { || Len( aArray ) }
    oBrw:bGoTop    = { || nCur := 1 }
    oBrw:bGoBottom = { || nCur := Len( aArray ) }
    oBrw:bSkip     = { | nSkip | Skipper( aArray, @nCur, nSkip ) }
    oBrw:cAlias    = "ARRAY"

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER

    RETURN NIL


STATIC FUNCTION SKIPPER( aArray, nCur, nSkip )

    LOCAL nOld := nCur

    nCur += nSkip

    IF nCur > LEN( aArray ); nCur = LEN( aArray ); ENDIF
    IF nCur < 1; nCur = 1; ENDIF

    RETURN nCur - nOld
EMG

Posted: Thu Sep 18, 2008 7:57 pm
by Enrico Maria Giordano
Ops! The above is for FWH. Please test it using FWPPC (remember to change the #include).

EMG

Posted: Mon Sep 22, 2008 8:32 am
by yardenmo
Antonio and EMG,

Thanks.

With: SELECT Nombre FOR "Laureano" TO "Paco"
Can the SELECT / FOR be with more than one field?
like: FistName + FamilyName


I was trying EMG's example for arrays. It works good.
My problem is with the multi dimensional array filled from a data base. I'm trying the enclosed code and receive error:


LOCAL aArray := { {}, {}, {} }
LOCAL nCur := 1
LOCAL oWnd, oBrw
//
DO WHILE !MasLoad->( EOF() )
AADD( aArray[1], MasLoad->ContNumber )
AADD( aArray[2], Str( MasLoad->ContSize, 2 ) )
AADD( aArray[3], MasLoad->ContKind )
MasLoad->( dbSkip() )
ENDDO

DEFINE WINDOW oWnd TITLE "Status "

@ 1, 1 LISTBOX oBrw FIELDS;
IF( EMPTY( aArray ), "", aArray[ nCur, 1 ] ),;
IF( EMPTY( aArray ), "", aArray[ nCur, 2 ] ),;
IF( EMPTY( aArray ), "", aArray[ nCur, 3 ] );
HEADERS "Container", "Size", "Type" ;
SIZE 220, 167
oBrw:bLogicLen = { || Len( aArray ) }
oBrw:bGoTop = { || nCur := 1 }
oBrw:bGoBottom = { || nCur := Len( aArray ) }
oBrw:bSkip = { | nSkip | Skipper( aArray, @nCur, nSkip ) }
oBrw:cAlias = "ARRAY"

@ 12, 2 BUTTON "Dlg" SIZE 80, 30 ACTION MsgInfo( aArray[ nCur, 1 ] )

@ 12,17 BUTTON "Done" SIZE 80, 30 ACTION oWnd:End()

ACTIVATE WINDOW oWnd ON CLICK MsgInfo( "Click!" )


Thanks,
Moshe Yarden

Posted: Mon Sep 22, 2008 10:00 am
by Enrico Maria Giordano
Try

Code: Select all

IF( EMPTY( aArray ), "", aArray[ 1, nCur ] ),;
etc.

EMG

Posted: Mon Sep 22, 2008 12:07 pm
by yardenmo
Thanks.

With : IF( EMPTY( aArray ), "", aArray[ 1, nCur ] ),;
It doesn't give error, however it shows just 3 records when there are about 180.

I changed to use 3 arrays and it looks ok now.


Thanks again,

Moshe Yarden

Posted: Mon Sep 22, 2008 2:13 pm
by Enrico Maria Giordano
You have to replace

Code: Select all

Len( aArray )
with

Code: Select all

Len( aArray[ 1 ] )
EMG