Rafael,

I’m glad that Koen’s solution works for you, but it seems like it would be very 
slow if 2/3 of the records meet “mycondition.”  I prefer to create a file that 
contains the value of the index key of the main file every 1% of the way 
through.  Then regardless of how one gets to a record in the indexed file, the 
value of the index key just has to be compared to the reference file.

It makes more sense with sample code:

CLOSE ALL
USE MyFile ORDER 1
DO Create_File_Position_Table    && Call only when file must be rebuilt

SEEK "BROWN"
? alltrim(str(Find_File_Position())) + "% from top"


PROCEDURE Create_File_Position_Table
DIMENSION aFilePos(101)
nWorkArea = select(0)
SET SAFETY OFF
CREATE TABLE FilePos FREE (Key_Field C(10))
SET SAFETY ON
SELECT (nWorkArea)
GO TOP
APPEND BLANK IN FilePos
REPLACE FilePos.Key_Field WITH replicate(" ", 10)
SKIP reccount() / 100 - 1
FOR i = 2 TO 100
    APPEND BLANK IN FilePos
    REPLACE FilePos.Key_Field WITH left(evaluate(key()), 10)
    SKIP reccount() / 100
  NEXT
APPEND BLANK IN FilePos
REPLACE FilePos.Key_Field WITH replicate("z", 10)
RETURN


FUNCTION Find_File_Position
nWorkArea = select(0)
cKey_Content = evaluate(key())
SELECT FilePos
LOCATE ALL FOR cKey_Content <= Key_Field
SELECT (nWorkArea)
RETURN recno("FilePos") – 1

Mike


--------------------------------------------------------------------------------


From: Rafael Copquin 
Sent: Monday, March 23, 2015 5:11 PM
To: profoxt...@leafe.com 
Subject: Re: record position

I know it sounds like a silly requirement, but my client wants to show 
the record position as a "page"

In any case, I tried your solution and it works very well.

Thank you very much

Rafael


El 23/03/2015 a las 19:51, Koen Piller escribió:
> Rafael,
> what is the use? The recordposition in an ordered table is completely
> meaningless.
> If you realy must now the postiion of your cursor in an ordered table I
> would say you will have to build a counter, something in the line of:
> lnCounter = 0
> go top
> do while field=mycondition
> lnCounter = lnCounter +1
> skip
> enddo
> ? lnCounter
> Cheers,
> Koen
>
>
> 2015-03-23 23:34 GMT+01:00 Rafael Copquin <rcopq...@fibertel.com.ar>:
>
>> I have this cursor containing a list of clients.
>>
>> If I do not set any order (set order to 0), the records are shown in
>> physical order, so if I move the pointer 100 positions down, the record
>> position is given by recno(), in this case it would be 100.
>>
>> However, if I order the records by company name and move the record
>> pointer 100 records down, even though the position would be 100 records
>> from the top, recno() is not going to tell me where I am.
>>
>> I need to show that I am in the 100dhs position from the top, regardless
>> of the order.
>> I am dealing with a table containing 3 million records, and the
>> requirement is that the record position be shown very fast.
>>
>> To clarify, I select the table with the 3KK records and try to find a
>> certain company. Because the table is now ordered by company name, I can't
>> use recno() to tell in which position the found company is. If I move the
>> pointer down or up, the position should move one up or down.
>>
>> For instance, seek 'WIDGET CO'
>>
>> The actual record number, as per recno() could be 2348897. However that
>> record position in the cursor could be 1200, if the pointer is moved one
>> down, the position would be 1201, or if it were to be moved one up, the
>> position would be 1199.
>>
>> So, how can I determine the record position as opposed to recno() if the
>> table is in any particular order, such as company name ?
>>
>> Is there a function that can be used?
>>
>> Rafael Copquin
>>
>>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/FA55632810084FD893240A4BE36E082C@Studio17
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to