home *** CD-ROM | disk | FTP | other *** search
- // Tbex19.prg
- //
- // DbLookup function, accepting FOR and WHILE clauses
- //
- // Must link with Tbutils, Dict
-
- #include "Inkey.ch"
-
- // Default column separator
- #define DEF_CSEP " " + chr(179) + " "
-
- // Default heading separator
- #define DEF_HSEP chr(205) + chr(209) + chr(205)
-
- // Default footing separator
- #define DEF_FSEP chr(205) + chr(207) + chr(205)
-
- // Increment last character of a string. Useful for scoped tbrowses
- #define INCLAST(c) substr(c, 1, len(c) - 1) + ;
- chr( asc( substr( c, len(c) ) ) + 1)
-
- FUNCTION Test
-
- LOCAL bGoFirst
- LOCAL bGoLast
- LOCAL bWhile
- LOCAL bFor
- LOCAL cSearcher := "S"
-
- FIELD Lname
-
- // If we do not find a record goto 0
- bGoFirst := {|| DbSeek(cSearcher) }
- bGoLast := {|| DbSeek(INCLAST(cSearcher), .T.), ;
- DbSkip(-1) }
- bWhile := {|| Upper(Lname) = cSearcher }
- bFor := {|| .T. }
-
- CLEAR SCREEN
- DbLookup("tbdbf1", "tbdbf1", {"Lname", "Fname", "Acbal"}, ;
- bGoFirst, bGoLast, bWhile, bFor)
- ? Recno()
-
- RETURN NIL
-
-
- FUNCTION DbLookup(cDbfName, cNtxName, aFieldNames, ;
- bGoFirst, bGoLast, bWhile, bFor)
-
- LOCAL nSaveSel := Select()
- LOCAL oTbr := TBrowseDB(11, 11, 19, 69)
- LOCAL cSaveScr := SaveScreen(10, 10, 20, 70)
- LOCAL nField
- LOCAL oTbcTemp
- LOCAL lExitRequested := .F.
- LOCAL nKey
-
- oTbr:headSep := DEF_HSEP
- oTbr:footSep := DEF_FSEP
- oTbr:colSep := DEF_CSEP
-
- @ 10, 10 TO 20, 70
- USE (cDbfName) NEW INDEX (cNtxName)
-
- // See section called general purpose while and for condition
- // for details of these filtered browse routines, and tb12.prg
- oTbr:goTopBlock := {|| TBFwFirst(bGoFirst, bWhile, bFor) }
- oTbr:goBottomBlock := {|| TBFwLast(bGoLast, bWhile, bFor) }
- oTbr:skipBlock := {|n| TBFwSkip(n, bWhile, bFor) }
-
- // Create and add a TBColumn object for each database field in
- // the aFieldNames array
- FOR nField := 1 TO Len(aFieldNames)
- oTbcTemp := TBColumnNew(aFieldNames[nField], ;
- FieldBlock(aFieldNames[nField]))
- oTbr:addColumn(oTbcTemp)
- NEXT
-
- oTbr:goTop()
-
- DO WHILE !lExitRequested
- DO WHILE !oTbr:stabilize()
- ENDDO
- nKey := InKey(0)
- IF !StdMeth(nKey, oTbr)
- DO CASE
- CASE nKey == K_ESC .OR. nKey == K_ENTER
- lExitRequested := .T.
- ENDCASE
- ENDIF
- ENDDO
-
- SELECT (nSaveSel)
- RestScreen(10, 10, 20, 70, cSaveScr)
-
- RETURN NIL