# 2 Re: ASP Calendar not displaying events
Here is the code that calls the information and creates the calendar:
<%
' This function finds the last date of the given month
Function GetLastDay(intMonthNum, intYearNum)
Dim dNextStart
If CInt(intMonthNum) = 12 Then
dNextStart = CDate( "1/1/" & intYearNum)
Else
dNextStart = CDate(intMonthNum + 1 & "/1/" & intYearNum)
End If
GetLastDay = Day(dNextStart - 1)
End Function
' This routine prints the individual table divisions for days of the month
Sub Write_TD(sValue, sClass)
Response.Write " <TD ALIGN='left' WIDTH=20 HEIGHT=90 VALIGN='top' CLASS='"
& sClass & "'> " & sValue & "</TD>" & vbCrLf
End Sub
' Constants for the days of the week
Const cSUN = 1, cMON = 2, cTUE = 3, cWED = 4, cTHU = 5, cFRI = 6, cSAT =
7
' Get the name of this file
sScript = Request.ServerVariables("SCRIPT_NAME")
' Check for valid month input
If IsEmpty(Request("MONTH")) OR NOT IsNumeric(Request("MONTH")) Then
datToday = Date()
intThisMonth = Month(datToday)
ElseIf CInt(Request("MONTH")) < 1 OR CInt(Request("MONTH")) > 12 Then
datToday = Date()
intThisMonth = Month(datToday)
Else
intThisMonth = CInt(Request("MONTH"))
End If
' Check for valid year input
If IsEmpty(Request("YEAR")) OR NOT IsNumeric(Request("YEAR")) Then
datToday = Date()
intThisYear = Year(datToday)
Else
intThisYear = CInt(Request("YEAR"))
End If
strMonthName = MonthName(intThisMonth)
datFirstDay = DateSerial(intThisYear, intThisMonth, 1)
intFirstWeekDay = WeekDay(datFirstDay, vbSunday)
intLastDay = GetLastDay(intThisMonth, intThisYear)
' Get the previous month and year
intPrevMonth = intThisMonth - 1
If intPrevMonth = 0 Then
intPrevMonth = 12
intPrevYear = intThisYear - 1
Else
intPrevYear = intThisYear
End If
' Get the next month and year
intNextMonth = intThisMonth + 1
If intNextMonth > 12 Then
intNextMonth = 1
intNextYear = intThisYear + 1
Else
intNextYear = intThisYear
End If
' Get the last day of previous month. Using this, find the sunday of
' last week of last month
LastMonthDate = GetLastDay(intLastMonth, intPrevYear) - intFirstWeekDay
+ 2
NextMonthDate = 1
' Initialize the print day to 1
intPrintDay = 1
' Open a record set of schedules
Set Rs = Server.CreateObject("ADODB.RecordSet")
sSQL = "SELECT * FROM tEvents "
' These dates are used in the SQL
dFirstDay = intThisMonth & "/1/" & intThisYear
dLastDay = intThisMonth & "/" & intLastDay & "/" & intThisYear
'Response.Write sSQL
' Open the RecordSet with a static cursor. This cursor provides bi-directional
navigation
Rs.Open sSQL, sDSN, adOpenStatic, adLockReadOnly, adCmdText
%>
<%
' Initialize the end of rows flag to false
EndRows = False
Response.Write vbCrLf
' Loop until all the rows are exhausted
Do While EndRows = False
' Start a table row
Response.Write " <TR>" & vbCrLf
' This is the loop for the days in the week
For intLoopDay = cSUN To cSAT
if intLoopDay = cSun then
response.write("<tr>")
end if
' If the first day is not sunday then print the last days of previous
month in grayed font
If intFirstWeekDay > cSUN Then
Write_TD LastMonthDate, "NON"
LastMonthDate = LastMonthDate + 1
intFirstWeekDay = intFirstWeekDay - 1
' The month starts on a sunday
Else
' If the dates for the month are exhausted, start printing next month's
dates
' in grayed font
If intPrintDay > intLastDay Then
Write_TD NextMonthDate, "NON"
NextMonthDate = NextMonthDate + 1
EndRows = True
Else
' If last day of the month, flag the end of the row
If intPrintDay = intLastDay Then
EndRows = True
End If
dToday = CDate(intThisMonth & "/" & intPrintDay & "/" & intThisYear)
' iterate through the record set displaying events that overlap todays
date
if not RS.EOF then
bEvents = false
bPrintedTodaysTDTag = false
call RS.MoveFirst()
do while not RS.EOF
if dToday >= RS( "Start_Date" ) and dToday <= RS( "End_Date" ) then
'we have an event for today
bEvents = true
if not bPrintedTodaysTDTag then
' display the special red day link
Response.Write( "<td class='EVENT' valign='top' height=120 width=100>"
)
' display the link to the detailed events
Response.Write( "<A HREF=events1.asp?date=" &Server.URLEncode(dToday)
& " CLASS='event' > " & intPrintDay & "</A>" & "<P>" )
bPrintedTodaysTDTag = true
end if
' display the goodies for today
Response.Write( "<FONT Class='text2'>" )
Response.Write( RS( "Event_Title" ) & "<P>" )
Response.Write( "</FONT>" )
elseif dToday < RS( "Start_Date" ) then
exit do
if intLoopDay = cSat then
Response.Write( "</tr>" )
end if
end if
' move to the next record set element
call RS.MoveNext()
loop
if not bEvents then
' display the standard day number
Response.Write( "<td class='NOEVENT' VALIGN='top' height=120 width=100>"
)
Response.Write( intPrintDay )
end if
' close the table tag
Response.Write( "</td>" )
end if
if intLoopDay = cSat then
Response.Write( "</tr>" )
end if
end if ' intPrintDay > intLastDay
' Increment the date. Done once in the loop.
intPrintDay = intPrintDay + 1
End If
next ' intLoopDay = cSUN to cSAT
loop ' Do While EndRows = False
Rs.Close
Set Rs = Nothing
%>
"Douglas J. Steele" <djsteele@idirect.com> wrote:
>There were a couple of entries at the beginning of October when I went to
>look.
>
>Perhaps you should post the relevant portion of your ASP code, rather than
>us just looking at the end result of it running.
>
>--
>
>Doug Steele, Microsoft Access MVP
>Beer, Wine and Database Programming. What could be better?
>Visit "Doug Steele's Beer and Programming Emporium"
>http://I.Am/DougSteele/
>
>
>mike <michael.linster@tgdcom.com> wrote in message
>news:3958bca4$1@news.dev-archive.com...
>>
>> I have an ASP calendar that is working from present day until October,
>than
>> it won't display any events until 2001, than it starts displayng them
>correctly.
>> I am not sure why and that is why I have come to you all to hopefully
het
>> some help.
>>
>> If you want to see the calendar and test it out for yourself it is at
>www.scte.org/aspcalendar/calendar.asp
>>
>> It has an MS Access database, and there is actually data for days during
>> october and november and december
>>
>> THanks for anyh help
>>
>> Michael
>
>
mike at 2007-11-11 23:42:13 >

# 3 Re: ASP Calendar not displaying events
I took a quick look at your code, and, to be perfectly blunt, it's bit of a
mish-mash!
To start with, you're define constants (cSun, cMon, etc.) that already exist
in VBScript (vbSunday, vbMonday, etc.)
Right after that definition, you have a block of code that references
'Request("MONTH")' 5 times in 9 lines of code. Assign it to a variable,
check if that variable's length is > 0, and proceed from there!
An awful lot of your code can be eliminated by learning a bit more about
what DateSerial can buy you. For example, Day(DateSerial(ThisYear,
ThisMonth, 0)) will give you the last day of the previous month, regardless
of whether it "wraps around". Similary, DateSerial(ThisYear, ThisMonth + 1,
1) will give you the first day of next month, again, regardless if it's
December or not.
Why don't you limit which rows your SQL brings back? You know the date
range: only bring back rows within that range! (and order them by date: if
you continue to loop through every recordset member for every date, it'll be
a little bit more efficient!)
I don't have a definite answer as to why you're having problems, but my
suggestion would be to use DateSerial everywhere you're creating a date.
Someplaces, you use "dFirstDay = intThisMonth & "/1/" & intThisYear", other
places you use "CDate(intThisMonth & "/" & intPrintDay & "/" &
intThisYear)", and in still other places you do use DateSerial. A suspicion
at the back of my mind is that you're running into problems with dates
perhaps being interpreted as strings: 10 is greater than 1, but less than 2.
If you make these changes, and still run into problems, let me know.
HTH
--
Doug Steele, Microsoft Access MVP
Beer, Wine and Database Programming. What could be better?
Visit "Doug Steele's Beer and Programming Emporium"
http://I.Am/DougSteele/
mike <mike@Mikelinster.com> wrote in message
news:3964e107$1@news.dev-archive.com...
>
> Here is the code that calls the information and creates the calendar:
>
> "Douglas J. Steele" <djsteele@idirect.com> wrote:
> >There were a couple of entries at the beginning of October when I went to
> >look.
> >
> >Perhaps you should post the relevant portion of your ASP code, rather
than
> >us just looking at the end result of it running.
> >
> >--
> >
> >Doug Steele, Microsoft Access MVP
> >Beer, Wine and Database Programming. What could be better?
> >Visit "Doug Steele's Beer and Programming Emporium"
> >http://I.Am/DougSteele/
> >
> >
> >mike <michael.linster@tgdcom.com> wrote in message
> >news:3958bca4$1@news.dev-archive.com...
> >>
> >> I have an ASP calendar that is working from present day until October,
> >than
> >> it won't display any events until 2001, than it starts displayng them
> >correctly.
> >> I am not sure why and that is why I have come to you all to hopefully
> het
> >> some help.
> >>
> >> If you want to see the calendar and test it out for yourself it is at
> >www.scte.org/aspcalendar/calendar.asp
> >>
> >> It has an MS Access database, and there is actually data for days
during
> >> october and november and december
> >>
> >> THanks for anyh help
> >>
> >> Michael
> >
> >
>