count for Repeat, not until =......

could we made repeat not using until next := 0 BEGIN FINDFIRST; REPEAT GET(“Entry No.”); DELETE; UNTIL NEXT = 0; END; → it delete all records for example I have 100 records and then I just want to delete 50 records so the other 50 are still exists could we delete them for count?

I think You have to use a FOR - TO loop instead…

i := recordvar.count;
FOR j := 1 TO (i - 50) DO BEGIN
IF j = 1 THEN
recordvar.FINDFIRST
ELSE
recordvar.NEXT;
recordvar.DELETE();
END;

(i & j are integer-variables)

But if You want to delete a number of records, why don’t You set the appropriate filters, and then use DELETEALL() instead of looping?

I’m using a little bit different
FOR j := 1 TO (Qty) DO BEGIN
IF j = 1 THEN
FINDFIRST
ELSE
NEXT;
DELETE();
END;
but it still won’t worked :frowning: qty variable is the count that i want to delete it
I have tried using delete all, but i didn’t use setfilter, so all of my records deleted I used this and just modified for count

by the way could we do the setfilter for count?

SETFILTER(“Entry No.”, “1…3”);

→ like these for 3 records

but i want to setfilters without parameter “1…3”, but 3

Hi Stan,

I’m a bit confused as to what Your intentions are but…

I think the reason why Your code desn’t work, could be because there are some issues regarding the adressing of the record-variable.
I have tested the code, and it worked as it should in my database.
That might very well also be the reason why Your DELETEALL ended up deleting all records in the table.

A DELETEALL will delete all records in a given table, that falls inside filters You set.
So if the DELETEALL You tried to use, ended up deleting all records, that can only happen if no filters at all were set.

Regarding using SETFILTER for the count…
You can easily use the value You counted, as parameter in the SETFILTER, if that’s what You ask.
But keep in mind that the value You counted (e.g. 50) not have any direct relation to the values of the records counted.
Say that You have counted 100 records, that does not mean that the records have “Entry No.” 1 to 100, but could very well be 250 to 349 or what ever.
So I don’t think that it is relevant to use the counted value directly in the SETFILTER.

However…
RecordVar.SETFILTER(‘1…%1’,Qty) should do what You ask of.

If You at all times want 50 records to be left in the table, after You run the deletion-batch You’re working on, then You could do something like this…
Record.SETFILTER(the filters needed);
Record.FINDLAST; // finds the very last record within the filter
Record.NEXT(-50); // jumps 50 rows back
EntryNoToFilterTo := Record.“Entry No.” - 1;

Then do a
RecordVar.SETFILTER(‘1…%1’,EntryNoToFilterTo);
RecordVar.DELETEALL();

EntryNoToFilterTo is a integer-variable.
I assume that DataType of “Entry No.” is Integer as well.

I’d like to suggest to the both of you to read about FINDFIRST and FINDLAST, because neither one of you seem to understand what it does.

These t

wo

I’d like to suggest to the both of you to read about FINDFIRST and FINDLAST, because neither one of you seem to understand what it does.

These t

hmmmmm

sure , your code is magnificent

at last i successfully generate it

yesterday i failed just because i wrong put in the trigger

heheh

thank you very much sander :slight_smile:

Hi Daniel,

Well the learning-curve never becomes horizontal… [:)]

So the problem here is that I use a FINDFIRST/FINDLAST in combination with a NEXT?
Instead I should have used FINDSET and FIND(’+’)?

Or am I totally missing the point here?

Yes the FINDFIRST and FINDLAST commands are intended to be used to retrieve only one record. If you need to loop through a set of records, you use FINDSET. Read the F1 help for these commands, like I suggested, and you will learn what they are supposed to be used for.