Re: Loop in Delphi

Posted by Jenny on February 24, 2006

In Reply to Loop posted by Werner on February 20, 2006

: i am sitting with a problem.
: I have a number sequence: 1-15.
: I have a button on my form wich inserts a new record into my database
: (Currentley only in dbf format).
: Everytime i push the button it must increment a certian field in the database called voucher.
: But if the field :Voucher reaches 15 the next insert must start at 1 again. I
: managed to get it incrementing by assingning it a var and telling it=1. but how do you get it to start from 1 again after 15 is reached?
: Here is the source code:

: procedure TForm1.Button1Click(Sender: TObject);
: var
: y : integer;
: begin
: table1.IndexName := 'voucherdex';
: table1.last;
: y := table1.fieldbyname('voucher').AsInteger;
: y := y + 1;
: // Check here
: if y > 15 then
: y := 1;
: table1.insert;
: table1.fieldbyname('voucher').AsInteger := y;
: end;

: How do i make it count from here again instead of staying stuck at 1?

Maybe you forgot this last line:;

If that's not the solution, can you describe in more detail what goes right and what goes wrong? Do you get the first 15 records with field "voucher" from 1 to 15? What happens if you click the button afterwards, does it always add record with "voucher" equal to 1?

Related Articles and Replies