FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Elegant way for lookup data in xbrowse
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Elegant way for lookup data in xbrowse

Posted: Fri Feb 02, 2018 02:20 PM
Hello,

I have a browse with lots of rowse (dbf 300.000) and I want to have a result from a colomnheader that I click on.



So if I click M7 then the calculation should begin and display the result as

Total Result

Send 2400
Uit 250
Bounce 110
...

So for every occurence of data, the same data should be added with 1

In my programming way, I would start a function,
select the master database
create a temp database
start the loop from masterdbf
every new item is added to temp, or cummulated with 1
afther the loop, display a browse with the result.

Works ok...

But Ive seens samples where there are functions being used like

AEval(), .... and others that seems to be able to do this stuff in only some small lines of code..

Any samples for this kind of statistic data retrieving ?
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Elegant way for lookup data in xbrowse

Posted: Sat Feb 03, 2018 12:58 PM
Please try this code.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oDlg, oBrw

   USE CUSTOMER SHARED
   DEFINE DIALOG oDlg SIZE 500,500 PIXEL TRUEPIXEL
   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "CUSTOMER" ;
      COLUMNS "FIRST", "CITY", "STATE" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :City:bLClickHeader := { |r,c,f,oCol| ShowCount( oCol ) }
      :State:bLClickHeader := { |r,c,f,oCol| ShowCount( oCol ) }
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil

function ShowCount( oCol )

   local cFieldName  := oCol:cExpr
   local cSql, oRs

   cSql  := "SELECT " + cFieldName + ", COUNT(*) AS Num FROM <CTABLE> GROUP BY " + cFieldName
   oRs   := ( oCol:oBrw:cAlias )->( FW_DBFSQLQUERY( nil, cSql, nil, .t. ) )
   XBROWSER oRs
   oRs:Close()
   oRs:ActiveConnection:Close()

return nil


Try clicking headers "City" and "State"

If you like you may adapt the logic.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Re: Elegant way for lookup data in xbrowse

Posted: Sat Feb 03, 2018 09:25 PM

Thanks !!

Works absolut perfect...in just 2 lines of code.

Very interesting sample ! Combination of Sql with dbf. This gives lot of potentials I think.

Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion