xBrowse Problem

xBrowse Problem

Postby Colin Haig » Tue Aug 02, 2011 7:15 am

Hi All

I have a small problem with footer calculations with xbrowse - I have created a sample program and test.dbf - how do I upload the files
for Mr Rao to check.

Cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: xBrowse Problem

Postby nageswaragunupudi » Wed Aug 03, 2011 5:28 am

Please send them by email to me.
nageswaragunupudi@gmail.com.
I shall post the solution here.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Problem

Postby nageswaragunupudi » Wed Aug 03, 2011 10:05 am

Received your mail.
This is the appropriate way of coding:
Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

function Main()

   local oWnd, oBrw

   fwNumFormat( 'A', .t., .f. )

   USE COLIN NEW SHARED VIA 'DBFCDX'

   DEFINE WINDOW oWnd
   SET MESSAGE OF oWnd TO '' 2007

   @ 0,0 XBROWSE oBrw OF oWnd ALIAS Alias() ;
      COLUMNS "Code", "DESC", "Qty", "Cost", "Charge" ;
      HEADERS  , "Description" ;
      PICTURES "@!" ;
      CELL LINES FOOTERS FASTEDIT

   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET
      :nStretchCol   := STRETCHCOL_WIDEST
      :lHScroll      := .f.
   END

   WITH OBJECT oBrw:Qty
      :nFooterType   := AGGR_SUM
      :bOnChange     := { ||  (oBrw:cAlias)->Charge := (oBrw:cAlias)->Qty * (oBrw:cAlias)->Cost, ;
                              oBrw:MakeTotals( oBrw:Charge ), oBrw:RefreshFooters() }
   END

   WITH OBJECT oBrw:Cost
      :nFooterType   := AGGR_SUM
      :bOnChange     := { ||  (oBrw:cAlias)->Charge := (oBrw:cAlias)->Qty * (oBrw:cAlias)->Cost, ;
                              oBrw:MakeTotals( oBrw:Charge ), oBrw:RefreshFooters() }
   END

   WITH OBJECT oBrw:Charge
      :nFooterType   := AGGR_SUM
      :bOnChange     := { ||  (oBrw:cAlias)->Cost := (oBrw:cAlias)->Charge / (oBrw:cAlias)->Qty, ;
                              oBrw:MakeTotals( oBrw:Cost ), oBrw:RefreshFooters() }
      :bEditWhen     := { || (oBrw:cAlias)->Qty > 0 }
   END

   oBrw:MakeTotals()
   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   ACTIVATE WINDOW oWnd

return 0
 

Please try this code. I am sure this works the way you expected.

Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Problem

Postby reinaldocrespo » Wed Aug 03, 2011 4:10 pm

Hi.

I have a problem with money fields where the totals on footer are shown with 4 decimal places instead of 2. How can I deal with that problem?

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: xBrowse Problem

Postby nageswaragunupudi » Wed Aug 03, 2011 7:38 pm

reinaldocrespo wrote:Hi.

I have a problem with money fields where the totals on footer are shown with 4 decimal places instead of 2. How can I deal with that problem?

Reinaldo.

I don't understand the problem.
Are the totals shown with 4 decimals by xbrowse, where as you want to show with 2 decimal places?

Can I see a sample code?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Problem

Postby reinaldocrespo » Wed Aug 03, 2011 8:00 pm

nageswaragunupudi wrote:Are the totals shown with 4 decimals by xbrowse, where as you want to show with 2 decimal places?

Can I see a sample code?


Correct. 4 decimals where it should be 2 decimal places.

It will take me a little while to write a reduced self contained sample for you to see. I will do that soon.

Thank you,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: xBrowse Problem

Postby nageswaragunupudi » Thu Aug 04, 2011 8:44 pm

Mr. Reinaldocrespo

I presume you are referring to money fields of ADS. DBStruct() of RDDADS shows 4 decimal places for money fields.

Hint:
XBrowse formats the footers also with the same picture clause specified in oCol:cEditPicture.

Please assign appropriate picture clause with 2 decimals to oCol:cEditPicture. Footers also will be diplayed accordingly.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Problem

Postby reinaldocrespo » Thu Aug 04, 2011 8:58 pm

Mr. Rao;

Yes. You are assuming correctly. Thank you very much for the hint, I should have thought of that!

Again, thank you very much.


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: xBrowse Problem

Postby nageswaragunupudi » Thu Aug 04, 2011 11:19 pm

Please ignore the sample I posted earlier. It works but not optimized. Below is an optimized version. Anyone who likes to adopt the logic, may follow this example, but not the first one,
Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

function Main()

   local oWnd, oBrw

   fwNumFormat( 'A', .t., .f. )

   USE COLIN NEW SHARED VIA 'DBFCDX'

   DEFINE WINDOW oWnd
   SET MESSAGE OF oWnd TO '' 2007

   @ 0,0 XBROWSE oBrw OF oWnd ALIAS Alias() ;
      COLUMNS "Code", "DESC", "Qty", "Cost", "Charge" ;
      HEADERS  , "Description" ;
      PICTURES "@!" ;
      CELL LINES FOOTERS FASTEDIT

   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET
      :nStretchCol   := STRETCHCOL_WIDEST
      :lHScroll      := .f.
   END

   WITH OBJECT oBrw:Qty
      :nFooterType   := AGGR_SUM
      :bOnChange     := { || oBrw:Charge:PostEdit( oBrw:Qty:Value * oBrw:Cost:Value ) }
   END

   WITH OBJECT oBrw:Cost
      :nFooterType   := AGGR_SUM
      :bOnChange     := { || oBrw:Charge:PostEdit( oBrw:Qty:Value * oBrw:Cost:Value ) }
   END

   WITH OBJECT oBrw:Charge
      :nFooterType   := AGGR_SUM
      :bEditWhen     := { || (oBrw:cAlias)->Qty > 0 }
      :bOnChange     := { || oBrw:Cost:PostEdit( oBrw:Charge:Value / oBrw:Qty:Value ) }
   END

   oBrw:MakeTotals()
   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   ACTIVATE WINDOW oWnd

return 0
 


From version 11.08, instead of PostEdit, use VarPut.

The method MakeTotals() scans the entire database to compute the totals. This method is not optimized for speed, but intended to provide some computational flexibility for different aggregates like averages, standard deviations, etc and takes into account null values and non-numeric values in some rows. For small and medium sized tables, the performance can be satisfactory, but it is desirable to use pre-computed totals for medium, and large tables.

That is the reason why should try to avoid using the Method MakeTotals() inside the program every time some values are changed.

When some cells are edited, XBrowse recomputes the totals and refreshes the footers automatically. For this purpose, XBrowse does NOT retotal by calling MakeTotals(). Instead xBrowse increases the oCol:nTotal by the difference between the edited value and the old value. This way, xBrowse's built-in updation of totals is very fast, avoiding any disk access. Same is true even for complex aggregates like averages, standard deviations, etc.

In the revised sample, I avoided calling MakeTotals when cells are edited and instead depended on the xbrowse's internal updating logic.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 136 guests