filtering records in xbrowse

filtering records in xbrowse

Postby Ehab Samir Aziz » Sat Dec 16, 2006 8:10 am

Image

That first record is deifferent from my filter condition . I am using go top after set filter and I do not know why I can see different record from my filter scope .

Code: Select all  Expand view
STATIC FUNCTION mete( oWnd )
*--------------------------
   local oChild, oBrw
   Local oDlgn, oDbfc, oBrwc

   local nRecNo  := RecNo()
   local new_rec  := 0
   local oGet
   local i:=0
   local nFor
   local bFilter := ""
   local cFilter := ""
   local x := ""

REQUEST ADS
rddRegister( "ADS", 1 )
rddsetdefault( "ADS" )
AdsSetDeleted(.T.)
SET SERVER LOCAL
SET FILETYPE TO CDX




x := "'9855564'"
cFilter := "me_mc_serl = "+ x
bFilter = "{||"+cFilter+"}"


SELECT 4
use mete
SET index TO mete2
DBSETFILTER(&bFilter,cFilter)
4->(DBGOTOP())




DEFINE DIALOG oDlgn  FROM 1,1 TO 50,140 TITLE "Dialog Meter Works"



   oBrw := TXBrowse():New( oDlgn )
   oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:nRowDividerStyle    := LINESTYLE_BLACK
   oBrw:lColDividerComplete := .t.
   oBrw:nHeaderLines        := 1
   oBrw:nFooterLines        := 1
   oBrw:nDataLines          := 1
   oBrw:lFooter             := .t.
   oBrw:SetRDD()

SELECT 4
use mete
SET index TO mete2
DBSETFILTER(&bFilter,cFilter)
4->(DBGOTOP())

oBrw:Refresh(.t.)

   for nFor := 1 to Fcount()

   *if (nFor<16)
   *   loop
   *endif

   if nFor=21
      oBrw:aCols[ nFor ]:cHeader       := FieldName( nFor )
      oBrw:aCols[ nFor ]:cFooter       := alltrim(STR(TOTALEM2(),12,0))
      loop
   endif
      *oBrw:aCols[ nFor ]:cHeader       := FieldName( nFor )
      *oBrw:aCols[ nFor ]:cFooter       := FieldName( nFor )
   next





   @ 18, 1 BUTTON "&New"    OF oDlgn SIZE 40, 12 ACTION addmeter( oLbx, .t. )
   @ 18, 8 BUTTON "&Modify" OF oDlgn SIZE 40, 12  //ACTION Editmach( oLbx, .f. )
   @ 18, 15 BUTTON "&Delete" OF oDlgn  SIZE 40, 12  //ACTION Delrecord( oLbx )
   @ 18, 22 BUTTON "&Search" OF oDlgn SIZE 40, 12 //ACTION Seekmach( oLbx )
   @ 18, 29 BUTTON "&Print"  OF oDlgn ;
      SIZE 40, 12;
      ACTION oBrw:Report( "Machines Report", .t. ) ;  // .t. --> wants preview


   @ 18, 36 BUTTON "&Exit"   OF oDlgn ACTION oDlgn:End() SIZE 40, 12

   @ 19,  1 BUTTON "&Order"    OF oDlgn SIZE 40, 12 //ACTION ordermach(oLbx)
   @ 19,  8 BUTTON "&Filter"    OF oDlgn SIZE 40, 12 //ACTION metefilter(oLbx)
   @ 19,  15 BUTTON "&Unfilter" OF oDlgn SIZE 40, 12 //ACTION filtermachNotOk(oLbx)



   oBrw:CreateFromCode()

return nil
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby areang » Sat Dec 16, 2006 9:55 am

Ehab Amir Azis wrote
Code: Select all  Expand view
SELECT 4
use mete
SET index TO mete2
DBSETFILTER(&bFilter,cFilter)
4->(DBGOTOP())



replace with this
Code: Select all  Expand view
   bFirst := {|| mete->(DbSeek(cFilter, .t. )) }
   bLast  := {|| iif(Empty(cFilter), ;
                     mete->(DbGoBottom()) , ;
                     (mete->(DbSeek(cFilter+"999",.T.)), ;
                     meter->(DbSkip(-1)))) }
   bWhile := {|| mete->your_fieldname_for_filter == cFilter }
   bFor   := {|| .T. }

   oBrw:bGoTop    := {||  TBFwFirst(bFirst, bWhile, bFor) }
   oBrw:bGoBottom := {||  TBFwLast(bLast, bWhile, bFor) }
   oBrw:bSkip     := {|n| TBFwSkip(n, bWhile, bFor) }



then add this source to your prg file

Code: Select all  Expand view
FUNCTION TBFwFirst(bGoFirst, bWhile, bFor)

  eval(bGoFirst)
  DO WHILE !eof() .AND. eval(bWhile) .AND. !eval(bFor)
    SKIP
  ENDDO

  IF !eval(bWhile)
    // no records match filter - could also be at eof already here
    GOTO 0
  ENDIF

RETURN NIL


FUNCTION TBFwLast(bGoLast, bWhile, bFor)

  eval(bGoLast)
  DO WHILE !bof() .AND. eval(bWhile) .AND. !eval(bFor)
    SKIP -1
  ENDDO

  IF bof() .OR. !eval(bWhile)
    // No records match scope
    GOTO 0
  ENDIF

RETURN NIL


FUNCTION TBFwSkip(nToSkip, bWhile, bFor)

LOCAL nSkipped := 0, ;
      nLastValidRecNum := Recno()

  IF nToSkip = 0
    SKIP 0
    RETURN 0
  ENDIF

  IF nToSkip > 0
    DO WHILE nSkipped < nToSkip .AND. !eof() .AND. eval(bWhile)
      SKIP
      // Note the last clause here makes a big speed difference
      DO WHILE !eval(bFor) .AND. !eof() .AND. eval(bWhile)
        SKIP
      ENDDO
      IF Eval(bWhile) .AND. !eof()
        // Found a new record matching the scope
        nSkipped++
        nLastValidRecNum := Recno()
      ENDIF
    ENDDO

    IF eof() .OR. !eval(bWhile)
      GOTO nLastValidRecNum
    ENDIF
  ELSE
    DO WHILE nSkipped > nToSkip .AND. !bof() .AND. eval(bWhile)
      SKIP -1
      // Note the last clause here makes a big speed difference
      DO WHILE !eval(bFor) .AND. !bof() .AND. eval(bWhile)
        SKIP -1
      ENDDO
      IF Eval(bWhile) .AND. !bof()
        nSkipped--
        nLastValidRecNum := Recno()
      ENDIF
    ENDDO
    IF !eval(bWhile) .OR. bof()
      GOTO nLastValidRecNum
    ENDIF
  ENDIF

RETURN nSkipped


Best Regard
areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Not exported variable

Postby Ehab Samir Aziz » Sat Dec 16, 2006 11:34 am

I got that error :
Not exported variable
Application
===========
Path and name: E:\programs\clipper\FWH\sitex\sitex.exe (32 bits)
Size: 1,527,808 bytes
Time from start: 0 hours 0 mins 6 secs
Error occurred at: 16/12/2006, 13:09:05
Error description: Error BASE/1005 No exported variable: BGOTOP
Args:
[ 1] = U
[ 2] = B {|| ... }

Stack Calls
===========
Called from: => _BGOTOP(0)
Called from: sitex.prg => METE(4534)
Called from: sitex.prg => (b)BUILDMENU(164)
Called from: => TMENU:COMMAND(0)
Called from: => TWINDOW:COMMAND(0)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: .\source\classes\WINDOW.PRG => _FWH(0)
Called from: => WINRUN(0)
Called from: => TWINDOW:ACTIVATE(0)
Called from: sitex.prg => MAIN(137)

Code: Select all  Expand view
STATIC FUNCTION mete( oWnd )
*--------------------------
   local oChild, oBrw
   Local oDlgn, oDbfc, oBrwc

   local nRecNo  := RecNo()
   local new_rec  := 0
   local oGet
   local i:=0
   local nFor
   local bFilter := ""
   local cFilter := ""
   local x := ""
   local bFirst,bLast,bWhile,bFor,bGoTop,bGoBottom,bSkip




REQUEST ADS
rddRegister( "ADS", 1 )
rddsetdefault( "ADS" )
AdsSetDeleted(.T.)
SET SERVER LOCAL
SET FILETYPE TO CDX




x := "'9855564'"
cFilter := "me_mc_serl = "+ x
bFilter = "{||"+cFilter+"}"

SELECT 4
use mete
SET index TO mete2

   bFirst := {|| mete->(DbSeek(cFilter, .t. )) }
   bLast  := {|| iif(Empty(cFilter), ;
                     mete->(DbGoBottom()) , ;
                     (mete->(DbSeek(cFilter+"999",.T.)), ;
                     mete->(DbSkip(-1)))) }
   bWhile := {|| mete->me_mc_serl == cFilter }
   bFor   := {|| .T. }

   oBrw:bGoTop    := {||  TBFwFirst(bFirst, bWhile, bFor) }
   oBrw:bGoBottom := {||  TBFwLast(bLast, bWhile, bFor) }
   oBrw:bSkip     := {|n| TBFwSkip(n, bWhile, bFor) }






DEFINE DIALOG oDlgn  FROM 1,1 TO 50,140 TITLE "Dialog Meter Works"



   oBrw := TXBrowse():New( oDlgn )
   oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:nRowDividerStyle    := LINESTYLE_BLACK
   oBrw:lColDividerComplete := .t.
   oBrw:nHeaderLines        := 1
   oBrw:nFooterLines        := 1
   oBrw:nDataLines          := 1
   oBrw:lFooter             := .t.
   oBrw:SetRDD()



oBrw:Refresh(.t.)

   for nFor := 1 to Fcount()

   *if (nFor<16)
   *   loop
   *endif

   if nFor=21
      oBrw:aCols[ nFor ]:cHeader       := FieldName( nFor )
      oBrw:aCols[ nFor ]:cFooter       := alltrim(STR(TOTALEM2(),12,0))
      loop
   endif
      *oBrw:aCols[ nFor ]:cHeader       := FieldName( nFor )
      *oBrw:aCols[ nFor ]:cFooter       := FieldName( nFor )
   next





   @ 18, 1 BUTTON "&New"    OF oDlgn SIZE 40, 12 //ACTION addmeter( oLbx, .t. )
   @ 18, 8 BUTTON "&Modify" OF oDlgn SIZE 40, 12  //ACTION Editmach( oLbx, .f. )
   @ 18, 15 BUTTON "&Delete" OF oDlgn  SIZE 40, 12  //ACTION Delrecord( oLbx )
   @ 18, 22 BUTTON "&Search" OF oDlgn SIZE 40, 12 //ACTION Seekmach( oLbx )
   @ 18, 29 BUTTON "&Print"  OF oDlgn ;
      SIZE 40, 12;
      ACTION oBrw:Report( "Machines Report", .t. ) ;  // .t. --> wants preview


   @ 18, 36 BUTTON "&Exit"   OF oDlgn ACTION oDlgn:End() SIZE 40, 12

   @ 19,  1 BUTTON "&Order"    OF oDlgn SIZE 40, 12 //ACTION ordermach(oLbx)
   @ 19,  8 BUTTON "&Filter"    OF oDlgn SIZE 40, 12 //ACTION metefilter(oLbx)
   @ 19,  15 BUTTON "&Unfilter" OF oDlgn SIZE 40, 12 //ACTION filtermachNotOk(oLbx)



   oBrw:CreateFromCode()

return nil


Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 91 guests

cron