Hello,
Is there a function to fill a array with unique values from a dbf field ?
Ex. STate has : A B C A B B B D
the array should have A,B,C,D
The purpose is in a Xbrowse to filter data with a combo from a
BarGet.
Using: FWH 23.08 with Harbour
Hello,
Is there a function to fill a array with unique values from a dbf field ?
Ex. STate has : A B C A B B B D
the array should have A,B,C,D
The purpose is in a Xbrowse to filter data with a combo from a
BarGet.
There is a "UNIQUE" clause for indexes:
INDEX … UNIQUE
That might help. However, It seems to me that you have already established the set of unique values, or are you going to let users enter new values too?
Perhaps you need a separate database for these.
I think we need more information.
James,
Asume the folowing
I will Xbrowse all Customers and many colums end have the getbars on top of Xbrowse.
I can put "Senford" in the col city, hit the filter button and I will have all customers from Senford.
No let say that I don't know the possible city's. Therefore I want to make a Combobox in the Xbrowse with the unique city's.
Your suggestion is right. I could make a temp dbf or index and then fill a array for the combo.
Maybe FW_dbftoarr has a option. I will look into it.
Thanks
aVals := {}
SET ORDER TO TAG STATEUNQ
DBGOTOP()
DBEVAL( { || AAdd( aVals, FIELD->STATE } ) OrdSetFocus( "STATE" )
DBGOTOP()
do while !Eof()
AADD( aVals, OrdKeyVal() )
OrdSkipUnique()
enddo INDEX ON STATE TAG STATEUNQ TO TMP MEMORY ADDITIVE UNIQUEaVals := {}
DBGOTOP()
DBEVAL( { || If( AScan( aVals, FIELD->STATE ) == 0, AAdd( aVals, FIELD->STATE ), nil ) } )
DBGOTOP()
ASORT( aVals )Thanks you for the options.
Some new technique's for me...

// You have a normal index on LAST ( not unique )
oCust:OrdSetFocus( "CUST1" )
oCust:GoTop()
do while !oCust:Eof()
AADD( aVals, { oCust:Last, oCust:First } )
oCust:OrdSkipUnique() // !!!! not possible
enddo// You have a normal index on LAST ( not unique )
oCust:OrdSetFocus( "CUST1" )
oCust:GoTop()
cStrTest := oCust:Last + oCust:First
lUnique := .F.
DO WHILE !oCust:Eof()
IF lUnique = .F.
AADD( aVals, { oCust:Last, oCust:First } )
ENDIF
oCust:Skip(+1)
// OrdSkipUnique() !!!
IF cStrTest = oCust:Last + oCust:First
lUnique := .T.
ELSE
lUnique := .F.
cStrTest := oCust:Last + oCust:First
ENDIF
ENDDO