Subject Re: PRG keeps looping back to start
From Gaetano De Luisi <gaetanodd@hotmail.com>
Date Sat, 11 Jul 2020 16:48:33 -0400
Newsgroups dbase.getting-started


I found what causes the code to execute in loops but I can't make sense of it. It's the RETURN statement at the end. If I remove it, the code does not get executed endlessly.

Any light you can shed on this would be appreciated.

Andy Taylor Wrote:

> Gaetano,
>
> If you get to the final msgbox then the program has completed.
> It MUST be being triggered from somewhere else to run again - what mechanism are you using to run the program in the first place?
>
> Andy
>
> > I have a do while loop to cycle through records to look for missing records for a time interval while .not.eof()
> >
> > From what I can tell, the initial DO WHILE loop EOF() condition evaluates to TRUE because the msgbox("End of do while was reached","Warning",64) does get triggered
> >
> > Nevertheless, after that msgbox is closed, the whole PRG file executes again instead of exiting. If there was a failure in the logic and EOF was never reached, I could understand that the routine would go in loops forever, but I cannot understand what triggers the loop-back to the start of the routine even though the DO WHILE does end and I do see the "GAP Found" timestamp value progressing to the last record.
> >
> > FYI, the reason I delete some records at the start is to create the gaps, because when there are no gaps, the code executes as expected, the logfile contains the timestamp of when it was run and "No gaps found!", and the program doesn't go back to the start of the routine once the last record is reached.
> >
> > What am I doing wrong?
> >
> > //integrity checks
> >
> > //log gaps in interval data
> > use energydata.dbf order etimestamp excl
> > goto top
> > delete all for Mins=55
> > pack
> > goto top
> > nCurrDay = dd
> > nCurrMins=Mins
> > skip 1
> > nNextDay = dd
> > nNextMins=Mins
> >
> > //create a logfile and store the rundate
> > logString=DTTOC(datetime())
> > logFile = "dataGroomLog.txt"
> >                         f=new file()
> >                         if f.exists(logFile)
> >                                 f.open(logFile,"A")
> >                         else
> >                                 f.create(logFile)
> >                         endif
> >                         f.writeln(LogString)        
> >                         logString="no gaps found!" //if no gaps are found, this is what will be logged
> >                         
> > do while .not. eof()
> >
> >         nCurrDay=nNextDay
> >         nCurrMins=Mins-5
> >         
> >         
> >         Do while nCurrDay=nNextDay                
> >
> >                 if nNextMins=nCurrMins+5 //all good, just the next 5 mins interval, update vars, skip and keep looping                
> >                         
> >                         nCurrmins=nNextmins
> >                         nCurrday=nNextday
> >                         skip 1
> >                         nNextmins=Mins
> >                         nNextday=dd
> >                 elseif nNextMins=nCurrMins-55 //all good, it's just a new hour, update vars, skip and keep looping                
> >                         nCurrmins=nNextmins
> >                         nCurrday=nNextday
> >                         skip 1
> >                         nNextmins=Mins
> >                         nNextday=dd
> >                 else // if it's neither a next 5 mins nor a new hour, it's a gap
> >                         msgbox("Gap found for timestamp: "+ eTimeStamp+"--nCurrMins="+nCurrMins+"--nNextMins="+nNextMins,"Warning",64)
> >                         //since a gap was found, update logString to the timestamp of the record and log it in a log file, update vars, skip and keep looping
> >                         logString=DTTOC(eTimeStamp)
> >                         f.writeln(logString)
> >                         //update vars and move pointer to the next record
> >                         nCurrmins=nNextmins
> >                         nCurrday=nNextday
> >                         skip 1
> >                         nNextmins=Mins
> >                         nNextday=dd                        
> >                 endif
> >                 
> >         enddo
> >         
> > enddo
> > f.writeln(logString)
> > msgbox("End of the main DO WHILE was reached","Warning",64)
> > close all
> > release all
> > return
>