Loop in Delphi

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);
  y : integer;
  table1.IndexName := 'voucherdex';
  y := table1.fieldbyname('voucher').AsInteger;
  y := y + 1;
  // Check here 
  if y > 15 then
    y := 1;
  table1.fieldbyname('voucher').AsInteger := y;

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

Thank you for your help
Regards, Werner

Related Articles and Replies