Q- Looping Problems

Q- Looping Problems

Post by Rick Whea » Thu, 16 May 1996 04:00:00



I'm working on a database application using Paradox 5.0 tables,
BDE and Delphi 1.02.

I have three tables in a 1-M-M relationship.  Clients(1), Debtors(M),
and Transactions(M).

I've designed the following procedures to loop through the Transaction
table and accumulate the total of all of a particular Debtor's
payments.

Logically, the code works.  I've set watches and observed it as it
iterates through the Transaction table, accumulating payments.  I've
watched it Update_Debtors by plugging the accumulated amount into the
appropriate field in the Debtor table.

My problem arises on the third debtor's update.  Upon returning to the
AccumulateTransactions procedure from the UpdateDebtor procedure, EOF
for the Transaction table becomes TRUE.  

I've attempted to make the procedures extremely understandable.  Please
offer some possible suggestions!

procedure TFrmMain.AccumulateTransactions (Sender: TObject);
   Begin
      {These are global variables}
      DebtorRecordNumber       := 0;
      ThisPaymentAmount        := 0;
      TotalPaymentAmount       := 0;
      UpdateDebtorRecordNumber := 0;

   with TblTransact do  {gentlemen, choose the table}
   begin
      TblTransact.IndexName := 'ByDebtorAndTransaction';  {set the index}
        TblTransact.First;  {start at first record}
        while not TblTransact.EOF do  {begin loop}
        begin
        if DebtorRecordNumber = 0 then   {yes on first pass, get value of debtor number}
           DebtorRecordNumber := TblTransact.FieldByName('DebtorNumber').AsInteger;

        if TblTransact.FieldByName('DebtorNumber').AsInteger > DebtorRecordNumber then
           UpdateDebtor(Sender);  {if this is a new debtor then update Debtor table}

        DebtorRecordNumber := TblTransact.FieldByName('DebtorNumber').AsInteger;

        ThisPaymentAmount := TblTransact.FieldByName('PaymentAmount').AsInteger;
        TotalPaymentAmount := ThisPaymentAmount + TotalPaymentAmount;

        UpdateDebtorRecordNumber := DebtorRecordNumber;

        TblTransact.Next;  {get the next transaction record}
        end;
   end;
end;

procedure TFrmMain.UpdateDebtor(Sender: TObject);
begin
   TblDebtor.IndexName := 'ByDebtorNumber';
   TblDebtor.Active := true;
   TblDebtor.SetKey;
   TblDebtor.Fields[0].AsInteger := UpdateDebtorRecordNumber;
   TblDebtor.GotoKey;
   TblDebtor.Edit;
   TblDebtor.FieldByname('TotalPayments').AsInteger := TotalPaymentAmount;
   TblDebtor.Post;
   TotalPaymentAmount := 0;
   ThisPaymentAmount := 0;
end;

On the third return from UpdateDebtor, regardless of the number of
transactions or debtors in the respective tables, EOF becomes true.
I can't seem to understand why.

Thanks in advance!

-- Rick
_____________________________________________________________
 Rick Wheat
 WheatWorks Software

 
 
 

1. Loops will not loop any more

Hello,

In a few of my DTS packages I use the looping process described in the
sqldts.com web site.  The process worked great.  But now when I run the
packages I get an error message from the step that sets the begin step to
"DTSStepExecStat_Waiting".  It tells me that it cannot find the begin step.
I cannot remember if this started after I installed SP3.  I am in
development with this and have just returned to it.

I have checked more than one package and get the same error.  I have
recreated new steps to loop to and a few other desperate attempts at getting
it to work again.

Any suggestions will be appreciated.

Thank you,

Paul Waters

2. Filter problems

3. HELP (VFP3) My Loop Doesn't Loop?

4. KILL NOT Removing Job

5. Looping within a Loop

6. placing snapshot file on a cluster

7. Need help with a loop script (won't loop)

8. Accessing Native OLE DB Driver

9. Help Help For Loops and incrementing fields each loop

10. newbie qs; examining databases and tables

11. Q- Temp files / VB / Access

12. newbie qs; fixing and checking databases

13. Multi Server Administration Qs