On Sun, 13 Jan 2008 02:36:52 GMT, "Stephen Quinn"
<stevejqNO@[EMAIL PROTECTED]
> wrote:
>
>> Function Swapcol()
<SNIP>
>> Return Nil
>> *********************************************************************
>>
>> The function is called when ever required.
>> I want to use for while condition in the above routine.
>
>What for??
>Your swapping 2 columns why would you need a while condition??
Steve, I think he wasn't speaking about the swapping but about the
tBrowsedbitself (i.e.tbrowse while the index key is a certain value,
for exemple for one customer, or for all customers in one city, or for
one product)
Mahesh, to achieve this, you need to make a custom skipblock. Make a
tbrowsenew() instead of tbrowsedb(), so you can define mb:skipblock
(see clipper'sNG or better, clipper's manuels for more help.
I've made a generic function for that purpose. See at the end of this
post. Then I call it this way
#define h_LAST .t. // for seek last
// tbrowsenew() instead of tbrowseDB()
ob := tbrowsenew( wRow(0), wCol(0), wMaxRow(), wMaxCol() )
// you define all ob:addcolumn(), ob:setkey() etc...
ob:GoTopBlock := { || dbseek(cThisCustomert) }
ob:SkipBlock := { |n| MovePointer(n, cThisCustomer) }
ob:GoBottomBlock := { || dbseek(cThisCustomer,, h_LAST) }
ob:gotop()
REPEAT
do while nextkey() == 0 .and. ! ob:stabilize()
enddo
UNTIL ( ob:ApplyKey(getkey(0)) == TBR_EXIT )
// ob:applyKey() is from clipper 5.3, it calls all the navigation
keys, in your case is all the "case Key = ENTER" etc...
// getkey() is my special inkey() with ol_yield()
/* -------------------------------- MovePointer
* Execut‚ par la methode skipblock lors d'un browse avec WHILE
(up,downn,
* pageup, pagedown)
* nToSkip donne le nb d'enr. … sauter (>0 ou <0), cOccurence est la
valeur
* par laquelle on filtre (ex : "100012"), bGiveOccurence donne la
* valeur de l'indice de l'enr courant (normalement, on le
defini ds la proc
* appelante par bGvOc =: &( "{|| indexkey(0)}" )
*
* Parametres :
* nToSkip : nb d'enr. … sauter (fourni par TBrowse)
* cOccurence : valeur de recherche
* bGiveKeyValue : (optionnel) l'evaluation de ce block donne la
valeur de
* l'index de l'enr. courant de la dbf courante . Par default,
ordkeyval()
*
* Retour : nb d'enr. effectivement saut‚s ( = ou < … nToSkip)
*
*/
#include "hcommon.ch" // Pour DEFAULT TO
function MovePointer(nToSkip, cOccurence, bGiveKeyValue)
local nSkipped := 0, nSens
DEFAULT bGiveKeyValue TO {|| ordkeyval()} // ok with rddcdx,
not with rddntx
if nToSkip == 0
SKIP 0
else // nToSkip != 0
// Direction dans laquelle on bouge :
nSens := nToSkip / abs(nToSkip)
do while !eof() .AND. !bof() ;
.AND. nSkipped != nToSkip ;
.AND. eval(bGiveKeyValue) = cOccurence
SKIP nSens // +1 ou -1
nSkipped += nSens
enddo
// Cas de sortie de la zone utile :
if eof()
nSkipped --
SKIP -1
elseif bof()
nSkipped ++
GOTO recno() // Pour reset du bof().
elseif !( eval(bGiveKeyValue) = cOccurence)
// On est sortit de l'occurence. On revient dedans.
SKIP -nSens
nSkipped -= nSens
endif Sortie de la zone utile
endif nToSkip == 0
RETURN nSkipped
*---- EoP MovePointer ----*
--
HTH,
Sebas


|