Page 1 of 1

XBROWSE Error on :nFooterType == AGGR_MIN

PostPosted: Thu Jun 08, 2017 6:54 am
by byte-one
In method MakeTotals() is an error with AGGR_MIN or AGGR_MAX. I have marked with //WHY and //ERROR

Code: Select all  Expand view
  if ! Empty( aCols )

      for each oCol in aCols
         WITH OBJECT oCol
            DEFAULT :nFooterType := AGGR_SUM
            :nTotal := :nTotalSq := 0.0
            :nCount := 0
            if :nFooterType == AGGR_MIN .or. :nFooterType == AGGR_MAX     //WHY
               :nTotal := Nil                          //WHY
            endif                     //WHY
         END
      next

      nCols    := Len( aCols )
      uBm      := ::BookMark()
      Eval( ::bGoTop )
      k := 1
      ::KeyCount()
      if ::nLen > 0
         do
            for each oCol in aCols
               WITH OBJECT oCol
                  nValue   := :SumValue()
                  if nValue != nil
                     :nCount++
                     if HB_ISNUMERIC( nValue )
                        if :nMinVal == nil .or. nValue < :nMinVal
                           :nMinVal   := nValue
                        endif
                        if :nMaxVal == nil .or. nValue > :nMaxVal
                           :nMaxVal   := nValue
                        endif
                        :nTotal    += nValue                             //ERROR as :nTotal above in code set to nil
                        :nTotalSQ  += ( nValue * nValue )
                     endif
                  endif
               END
            next n
         until ( ++k > ::nLen .or. ::Skip( 1 ) < 1 )
      endif

Re: XBROWSE Error on :nFooterType == AGGR_MIN

PostPosted: Thu Jun 08, 2017 9:33 am
by nageswaragunupudi
Mr Gunther

Thanks

We modify this code
Code: Select all  Expand view

            if :nFooterType == AGGR_MIN .or. :nFooterType == AGGR_MAX
               :nTotal := nil
            endif
 

as
Code: Select all  Expand view

            if :nFooterType == AGGR_MIN .or. :nFooterType == AGGR_MAX
               :nMinVal := nil // necessary
               :nMaxVal := nil // necessary
            endif
 


New thought to extend MAX and MIN to other types also
For the existing code:
Code: Select all  Expand view

                     if HB_ISNUMERIC( nValue )
                        if :nMinVal == nil .or. nValue < :nMinVal
                           :nMinVal   := nValue
                        endif
                        if :nMaxVal == nil .or. nValue > :nMaxVal
                           :nMaxVal   := nValue
                        endif
                        :nTotal    += nValue
                        :nTotalSQ  += ( nValue * nValue )
                     endif
 

we may substitute this new code
Code: Select all  Expand view

                     if :nMinVal == nil .or. nValue < :nMinVal
                        :nMinVal   := nValue
                     endif
                     if :nMaxVal == nil .or. nValue > :nMaxVal
                        :nMaxVal   := nValue
                     endif
                     if HB_ISNUMERIC( nValue )
                        :nTotal    += nValue
                        :nTotalSQ  += ( nValue * nValue )
                     endif
 

With this change we can have AGGR_MAX and AGGR_MIN for dates and character values also

What are your comments?

When the programmer sets AGGR_MAX or AGGR_MIN he is also responsible to ensure that all values of the column should of same datatype or nil.

Re: XBROWSE Error on :nFooterType == AGGR_MIN

PostPosted: Thu Jun 08, 2017 11:20 am
by byte-one
Ok, good!