FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DBeval for unique values
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
DBeval for unique values
Posted: Thu Jan 31, 2019 06:55 PM

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.

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: DBeval for unique values
Posted: Thu Jan 31, 2019 07:47 PM

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.

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: DBeval for unique values
Posted: Thu Jan 31, 2019 08:32 PM

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

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: DBeval for unique values
Posted: Thu Jan 31, 2019 09:13 PM
For example, we need an array of unique values of the field STATE from customer.dbf

Case-1:
If you already have a Unique Index on STATE.
Code (fw): Select all Collapse
aVals := {}
SET ORDER TO TAG STATEUNQ
DBGOTOP()
DBEVAL( { || AAdd( aVals, FIELD->STATE } )


Case-2:
You have a normal index on STATE ( not unique )
Code (fw): Select all Collapse
   OrdSetFocus( "STATE" )
   DBGOTOP()
   do while !Eof()
      AADD( aVals, OrdKeyVal() )
      OrdSkipUnique()
   enddo


Case-3:
You do not have index on STATE at all. (neither normal nor unique)
One option is to create a temporary index in memory:
Code (fw): Select all Collapse
   INDEX ON STATE TAG STATEUNQ TO TMP MEMORY ADDITIVE UNIQUE

Adopt the logic in Case-1.

Case-4
If we do not want to use indexes.
Code (fw): Select all Collapse
aVals := {}
   DBGOTOP()
   DBEVAL( { || If( AScan( aVals, FIELD->STATE ) == 0, AAdd( aVals, FIELD->STATE ), nil ) } )
   DBGOTOP()
   ASORT( aVals )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: DBeval for unique values
Posted: Thu Jan 31, 2019 10:18 PM

Thanks you for the options.

Some new technique's for me...

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: DBeval for unique values
Posted: Fri Feb 01, 2019 12:36 PM
Mr. Rao,

I added the 4 array unique-tests to the tDatabase-samples



This doesn't exist
Is there a replacement for it :-)

Case-2 and 3 :
oCust:OrdSkipUnique()

Code (fw): Select all Collapse
 
// 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


That skips unique records on normal index
changed to :

Code (fw): Select all Collapse
// 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


regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion