You can use binary search. Of a top of my head (not tested)
lnStart = 1
lnEnd = RECCOUNT()
lnMiddle = RECCOUNT()
lnRecnNo = 0
DO WHILE lnStart <= lnEnd
lnMiddle = INT(lnStart + lnEnd ) /2)
GOTO (lnMiddle)
IF NOT RLOCK()
lnStart = lnMiddle + 1
ELSE
lnEnd = lnMiddle - 1
IF lnRecno > 0
UNLOCK RECORD lnRecno
ENDIF
lnRecno = lnMiddle
ENDIF
ENDDO
>I’m trying to locate the next available unlocked record in a table.
>The table has about 150 records in it.
>
>When I use following code it may take 30 seconds if the 31 record is next available unlocked record and rLock() will return .T. but it is slow
>
>Sele the table
>scan
> IF rlock() = .t.
> ?rlock()
> endif
>endscan
>
>
>if I use this code it flies thru the isRlock function but will get .f. when it tries rLock()
>
>Sele the table
>scan
> IF isRlock() = .t.
> ?rlock()
> endif
>endscan
>
>What is the fasted way to do this?
--sb--