Subject Re: PRG keeps looping back to start
From Andy Taylor <andy.taylor.1959@outlook.com>
Date Sun, 12 Jul 2020 04:19:42 -0400
Newsgroups dbase.getting-started

Gaetano,

I have (very rarely) had this happen to me.  Code does not behave the way it should, and removing the code that failed, saving and then putting it back in has fixed the problem.  I just put it down to "a corrupt prg file that generated a consistent error in the compiled code".  As long as it happens almost never I'm not going to worry.

However, that does mean that if it happens to you again, you may well have forgotten this exchange and be equally perplexed again!

Andy
<big grin>

> hmmm, I have re-added the RETURN statement and now it doesn't execute in loops anymore. This is so weird. I did check that the PRO files were getting recompiled and they were.
>
> Thoughts?
>
> 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
> >
>