Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 Recurring Events (1st Mon,etc) - Code Help!
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

gelliott
Junior Member

USA
268 Posts

Posted - 19 July 2003 :  22:04:18  Show Profile
Everyone, my VBScript is timing out () when I test a improvement to Red's 6/4/03 Recurring Events Calendar Mod. I am trying to modify his code to allow choices like the 1st Monday of every month, or 4th Thursday of every month, or Last Wednesday of every month, etc. I have created options 18-52 in cal_post.asp which are as follows:

18 = 1st Mon
19 = 1st Tue
...
24 = 1st Sun
25 = 2nd Mon
...
45 = 4th Sun
46 = Last Mon
...
52 = Last Sun

I am now trying to design efficient code to calculate the appropriate dates. Instead of adding 35 more select statements, I am trying to be intelligent about it and only add 7 more, using the Events_Repeat variable as an indicator of which version of each weekday I want, then adding that many weeks to the first one found in each month. Naturally, this assumes I have found a way to find the 1st day of the following month. The "Last" cases are a little different, so I add an extra month to the 1st day of the month then subtract a week to find the last week of the month. The code I've written to add the above into cal_post_info1.asp and cal_post_info2.asp is as follows:
Case 18, 25, 32, 39, 46  '1st,2nd,3rd,4th,Last Mon (Monthly)
' step - find the 1st of the next month
dateCursor = DateAdd("d", -(1 - (DatePart("d",dateCursor))), dateCursor)  'backup to 1st of this month
dateCursor = DateAdd("m", 1, dateCursor)
if Event_Repeat = 46 then  'find the LAST one
	dateCursor = DateAdd("m", 1, dateCursor)  'Jump one month forward
	dateCursor = DateAdd("ww", -1, dateCursor) 'jump one week backward - now on last week of month
end if
'to compensate for DO loop adding one day before testing result
'which is no longer appropriate since I already changed dateCursor above
dateCursor = DateAdd("d", -1, dateCursor) 
Do
    dateCursor = DateAdd("d", 1, dateCursor)
Loop Until Weekday(dateCursor) = vbMonday
if Event_Repeat <> 18 and Event_Repeat <> 46 then
	dateCursor = DateAdd("ww", (Event_Repeat - 18) / 7, dateCursor)
end if

Note that I have not added any more loops other than what is in previous options, nor have I changed the exit loop criteria, so I am not sure why I end up in an infinite loop, if in fact that's what I'm in.

Can anybody see what I'm doing wrong? I'd love to get this working and post the required changes for everyone... Thanks in advance.

(edited for typos)

* The optimist says the cup is half full. The pessimist says it's half empty. But the engineer knows the truth - the cup's design is incorrectly sized.

Edited by - gelliott on 19 July 2003 22:08:42

gelliott
Junior Member

USA
268 Posts

Posted - 19 July 2003 :  22:16:33  Show Profile
OK, the "typos" I fixed in the previous post happened to be in my code as well (). Now is runs quickly but calculates crazy dates. Anybody see what's wrong?

* The optimist says the cup is half full. The pessimist says it's half empty. But the engineer knows the truth - the cup's design is incorrectly sized.
Go to Top of Page

gelliott
Junior Member

USA
268 Posts

Posted - 19 July 2003 :  22:33:45  Show Profile
OK, stupid me. I had my negative signs reversed. I'm testing my solution now, will post if it works...

* The optimist says the cup is half full. The pessimist says it's half empty. But the engineer knows the truth - the cup's design is incorrectly sized.
Go to Top of Page

gelliott
Junior Member

USA
268 Posts

Posted - 20 July 2003 :  11:50:59  Show Profile
Finished code posted at http://forum.snitz.com/forum/topic.asp?TOPIC_ID=46181...

* The optimist says the cup is half full. The pessimist says it's half empty. But the engineer knows the truth - the cup's design is incorrectly sized.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.31 seconds. Powered By: Snitz Forums 2000 Version 3.4.07