I am writing a routine in objectpal to get the top 25 customers into a table and subsequently a report. I can sort the table using "custTbl.attach" and "sort descending" like:
custTbl.attach("sortme.db") sort custTbl on ":PRIV:revenue" D to ":PRIV:sorted.db" endSort
But I need some form of TCursor loop or similar method to peel off the first (top) 25 customers.
I could not find a 'Top n' feature in Paradox Reports Currently using Paradox 11 with sp2. Any assistance or links to a solution appreciated.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
====================== movetorecno(), HELP This method is recommended only for dBASE tables. If used for a Paradox table, moveToRecNo behaves exactly like the moveToRecord method. ======================
tc.movetorecord(min(25,tc.nrecords())) Then do Cliff's stuff.
This way, if there are fewer than 25 records in the table, you are covered.
Also, you will probably want to open the table resulting from the copy and verify that there are only 25 records. You could have more than one with the exact 'revenue' value of that 25th record.
In case there are more than 25 after copy,
tc.open(":priv:top25.db") if tc.nrecords()>25 then tc.edit() tc.movetorecord(26) while true tc.deleterecord() if tc.recno()=25 then quitloop endif endwhile tc.endedit() endif tc.close()
Thanks for the help Cliff & Montana, it's good to know there is help out there. The code works fine as you suggested and is giving me the result I needed. I did however try out adding a variable, so the end user can enter on the form, say the top 30 or 50 customers depending on what's required. I made it something like this:
method pushButton(var eventInfo Event) var custTbl Table tv TableView darr dynArray[] anytype tc tCursor rev currency n String endVar n = qty custTbl.attach("sortme.db") sort custTbl on "revenue" D to "sorted.db" endSort tc.open("sorted.db") tc.moveToRecNo(n) rev = tc."revenue" darr["revenue"] = ">=" +string(rev) tc.setGenFilter(darr) tc.copy("top25.db") tv.open("top25.db") endMethod
where "qty" is a field on the form. This worked fine as well, until I entered a value >=70 then the whole table was returned. It turned out that I only had values in 69 records for 'revenue' the rest being blank or no sales. I will now try incorporating Montana's loop to remove '>n'records. Once again thanks for the assistance.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
tried: darr["revenue"] = "not blank, >=" +string(rev) But it returned the whole table :-( I guess "not blank" does not work the same as in queries in this instance. Overall though the primary objective has been achieved, thanks once again.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.