No, I think the code is not good.
Because you use a findfirst and choose a repeat afterwards (use findset or find('-'))
and second: next = 0 instead of next = -1 (This might be good, but I never use it) I find it too ambigous with next(-1)
|Pressing F1 is so much faster than opening your browser| |To-Increase|
I think if you want records in Descending Order and you do not get by findset after Ascending(False).
May be you need a key or doing some efforts by other way...
Regards,
Hemant They can conquer who believe they can.
Why do you think we didn't comment on the ascending: that part is correct.
ascending false will effectively sort the table in reverse.
The alternative was using a find('+') and using until table.next(-1) = 0
Mohanna, You ought not to use findfirst in a loop!
|Pressing F1 is so much faster than opening your browser| |To-Increase|
I'm starting to get confused. Help tells me findset can only be used in descending order, which tells me default ascending is already false: Could you try with ascending(true)?
if that doesn't work, use find('-')
And please don't use findfirst, it's not meant for looping. (findfirst does a select top(1) from table) if nav detects a loop it uses a second query. while findset and find('-') only use 1 query to get the data.
|Pressing F1 is so much faster than opening your browser| |To-Increase|
Item.ASCENDING(FALSE);
IF Item.FIND('-') THEN
REPEAT
Message('%1',Item."No.");
UNTIL Item.NEXT = 0;
This is the correct way. (or also ASCENDING(TRUE) and FIND('+') and NEXT(-1)
But in certain cases, a better way may exist.
The FIND('-') creates a cursor in SQL that is slow and heavy on the system.
If you have few records (<= # of records in recordset ; defined in File=Database=Alter=>Tab advanced), it is better to use FINDSET and read them in ASCENDING and save them in a temptable and then read them in descending. If you code is run a lot of times by a lot of users, this makes it a lot less heavy on the system.
Item.ASCENDING(TRUE); //Ascending!
IF Item.FINDSET THEN
REPEAT
tmpItem := Item;
tmpItem.INSERT(FALSE);
UNTIL Item.NEXT = 0;
tmpItem.RESET;
tmpItem.ASCENDING(FALSE);
IF tmpItem.FIND('-') THEN
REPEAT
Message('%1',tmpItem."No.");
UNTIL tmpItem.NEXT = 0;
Answers
Because you use a findfirst and choose a repeat afterwards (use findset or find('-'))
and second: next = 0 instead of next = -1 (This might be good, but I never use it) I find it too ambigous with next(-1)
|To-Increase|
try with:
take a look to "Next function (Record)" in OnLine help.
Edit: sorry to repeat what sog has already sad! =D>
It works as expected... More or Less...
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
I think if you want records in Descending Order and you do not get by findset after Ascending(False).
May be you need a key or doing some efforts by other way...
Hemant
They can conquer who believe they can.
FINDSET can only retrieve records in ascending order.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
ascending false will effectively sort the table in reverse.
The alternative was using a find('+') and using until table.next(-1) = 0
Mohanna, You ought not to use findfirst in a loop!
|To-Increase|
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
if that doesn't work, use find('-')
And please don't use findfirst, it's not meant for looping. (findfirst does a select top(1) from table) if nav detects a loop it uses a second query. while findset and find('-') only use 1 query to get the data.
|To-Increase|
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
|To-Increase|
But in certain cases, a better way may exist.
The FIND('-') creates a cursor in SQL that is slow and heavy on the system.
If you have few records (<= # of records in recordset ; defined in File=Database=Alter=>Tab advanced), it is better to use FINDSET and read them in ASCENDING and save them in a temptable and then read them in descending. If you code is run a lot of times by a lot of users, this makes it a lot less heavy on the system.
BTW: see also http://www.mibuso.com/howtoinfo.asp?FileID=22
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Usually you sould try to avoid Find('-') and Find('+') but in this senario you can ither
sort in descending order, find the first record and step forward:
or
sort in ascending order, find the last record and step backward: