Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUESTION WITH LOOPS

Status
Not open for further replies.

Volkmaniac

Technical User
Mar 19, 2003
104
0
0
US
I'm trying to run a script that calculates the current date, loops through, and then decrements the date by one month on every pass. I think I'm having a problem with one of the two loops because the statmsg will show that the month is decreasing but my strings sDate and sDate2 are not changing with each pass. Any help would be greatly appreciated.

while 1
dlgevent 0 Event
switch Event
case 0
endcase

case 141
disable DLGCTRL 0 141
capture on
winminimize $PWMAINWIN
for Loops = 0 upto 3
statmsg "Loop # %d" Loops
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

if iDay <= 31
endif

if Loops == 0
iMonth = iMonth
else
if Loops == 1
iMonth = iMonth - 1
else
if Loops == 2
iMonth = iMonth - 2

strfmt sDate "%02d-%02d-%d" iMonth iDay iYear
endif
endif
endif

if iDay2 <= 31

switch iMonth
case 1 ;January
case 3 ;March
case 5 ;May
case 7 ;July
case 8 ;August
case 10 ;October
case 12 ;December
iDay2 = 31 ;31 Days
endcase
case 4 ;April

case 5 ;May
case 6 ;June
case 9 ;September
case 11 ;November
iDay2 = 30 ;30 days
endcase
case 2 ;February
intsltime iYear iMonth iDay2 iHour iMin iSec TimeVal ;Convert to a long time value
ltimemisc TimeVal iWeekday iDayYear iLeapYear ;Get leap year value
if iLeapYear == 1 ;If leap year
iDay2 = 29 ;Set day to 29
else
iDay2 = 28
endif
endcase

endswitch
endif

strfmt sDate2 "%02d-%02d-%d" iMonth iDay2 iYear
strdelete sDate2 6 2

;......script portion
;end of loop


statmsg "Month %d" iMonth
loopfor
endif
exitfor
endfor


case 142
capture off
exit
exitwhile
endcase
endswitch
endwhile
winrestore $PWMAINWIN
dlgdestroy 0 CANCEL


 
Yes,

I ended up using a for loop.

while 1
dlgevent 0 Event
switch Event
case 0
endcase

case 141
disable DLGCTRL 0 141
capture on
winminimize $PWMAINWIN
for Loops = 0 upto 2
statmsg "Loop # %d" Loops
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

if iDay <=31
iDay = 1
endif

if Loops == 0
iMonth = iMonth
else
if Loops == 1
iMonth = iMonth - 1
else
if Loops == 2
iMonth = iMonth - 2

endif
endif
endif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top