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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do Nothing Loop

Status
Not open for further replies.

Quehay

Programmer
Feb 6, 2000
804
US
I have a function that uses a loop (see below) and when I step through it keeps returning a &quot;Loop without Do&quot; error message.&nbsp;&nbsp;WHY?&nbsp;&nbsp;Thanks!<br><br>Public Function NetWorkDays(StartDate As Date, EndDate As Date) As Integer<br>'Counts number of workdays between the two dates<br>'Requires: IsWeekend(bln) and IsHoliday(bln)<br><br><br>Function Name<br>Dim intCount As Integer<br>Dim dtmTemp As Date<br><br>'Get Holiday dates into array<br>MakeHolidayArray<br><br>dtmTemp = StartDate<br>intCount = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;Do While dtmTemp &lt; EndDate<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If IsWeekend(dtmTemp) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intCount = intCount<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ElseIf IsHoliday(dtmTemp, mHolidayArray) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intCount = intCount<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intCount = intCount + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br><br>NetWorkDays = intCount<br><br><br>
 
If that's all of your code then where is the<br>&quot;End if&quot; and &quot;End Function&quot;<br>Sometimes VBA gets confused. That problem has been around since VB3 or 4.<br>It thinks you are missing a Loop when you are really missing an &quot;END IF&quot;<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Does the same thing happen when you move the condition to the loop statement?&nbsp;&nbsp;<br><br>ie: <br>Loop While dtmTemp &lt; EndDate<br><br>Drew<br>
 
Thanks for the response Doug & Drew.&nbsp;&nbsp;Doug you got it--I thought I'd checked for that one--guess I'd been looking at the screen too long!
 
Hi QueHay,<br><br>shouldn't you be incrementing dtmTemp as this is the loop variant?<br><br><br>maybe<br><br>&nbsp;&nbsp;&nbsp;&nbsp;dtmTemp = StartDate<br>&nbsp;&nbsp;&nbsp;&nbsp;intCount = 0<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Do While dtmTemp &lt; EndDate<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If (not IsWeekend(dtmTemp) _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or not IsHoliday(dtmTemp, mHolidayArray)) then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' take it this is count of days<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' between date 1 and date 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' that are not w/eor not holidays<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intCount = intCount + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' increment though the number of days<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dtmTemp = dtmTemp + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;&nbsp;&nbsp;NetWorkDays = intCount<br><br>something like that you may need to consider the relation between holidays and weekends??<br><br>hope this helps<br><br>see ya<br>RobertD<br><br><br><br>Robert<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top