Help please, I've been working on a event calendar for my website, I've got thing working fine.
The month view is great, but what I'm looking for is produce a week view, with a link from the month view.
I've used the code below, which I found through another link on the forum (thnx to that person). But I can't seem to work out the Week view... I manage to take out the loop for the row cycle, but then I only end up with a single day... ie. 1st of that month...
can any one help... ??? thnx in advanced
<%
Dim objRecordset
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "calendar", MM_mercury_STRING, adOpenStatic, adLockPessimistic, adCmdTable
%>
<%
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " & iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
Function GetWeekdayMonthStartsOn(iMonth, iYear)
GetWeekdayMonthStartsOn = WeekDay(CDate("1" & "/" & iMonth & "/" & iYear))
End Function
Function SubtractOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 1 Then
iMonth = 12
iYear = iYear - 1
Else
iMonth = iMonth - 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then
iDay = GetDaysInMonth(iMonth, iYear)
SubtractOneMonth = CDate(iDay & "-" & iMonth & "-" & iYear)
End Function
Function AddOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 12 Then
iMonth = 1
iYear = iYear + 1
Else
iMonth = iMonth + 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
AddOneMonth = CDate(iDay & "-" & iMonth & "-" & iYear)
End Function
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim iPosition ' Variable we use to hold current position in table
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
If IsDate(Request.QueryString("day") & "-" & Request.QueryString("month") & "-" & Request.QueryString("year")) Then
dDate = CDate(Request.QueryString("day") & "-" & Request.QueryString("month") & "-" & Request.QueryString("year"))
Else
dDate = Date()
If Request.QueryString.Count <> 0 Then
Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
End If
End If
End If
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(Month(dDate), Year(dDate))
%>
<% Response.buffer = "true" %>
<%
'-- Monthly Cycle Table --
If iDOW <> 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
iPosition = 1
Do While iPosition < iDOW
Response.Write(vbTab & vbTab & "<td class='CalNoDay'> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
End If
'-- Write days of month in proper day slots --
iCurrent = 1
iPosition = iDOW
Do While iCurrent <= iDIM
'-- open the table row --
If iPosition = 1 Then
Response.Write(vbTab & "<tr bgcolor=white>" & vbCrLf)
End If
'-- Write the date and subject --
Response.Write(vbTab & vbTab & "<td width=100 height=70 align=left valign=top class='CalDay'>" &_
" <a href='add_event.asp?Y=" & Year(dDate) & "&M=" & Month(dDate) & "&D=" & iCurrent & "' class='CalDayLink'>" & iCurrent & "</a><br>")
If Not objRecordset.BOF Then
objRecordset.MoveFirst
Do Until objRecordset.EOF
If objRecordset.Fields("Year") = Year(dDate) Then
If objRecordset.Fields("Month") = Month(dDate) Then
If objRecordset.Fields("Day") = iCurrent Then
Response.Write("<a class='CalEventLink' href='display_event.asp?ID=" & objRecordset.Fields("ID") & "'>" & objRecordset.Fields("Subject") & "</a><br>")
End If
End If
End If
objRecordset.MoveNext
Loop
End If
Response.Write("</td>" & vbCrLf)
'-- Close the table row --
If iPosition = 7 Then
Response.Write vbTab & "</tr>" & vbCrLf
iPosition = 0
End If
'-- Increment variables --
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write(vbTab & vbTab & "<td class='calNoDay'> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
Response.Write vbTab & "</tr>" & vbCrLf
End If
'-- End of Monthly cycle --
%>
The month view is great, but what I'm looking for is produce a week view, with a link from the month view.
I've used the code below, which I found through another link on the forum (thnx to that person). But I can't seem to work out the Week view... I manage to take out the loop for the row cycle, but then I only end up with a single day... ie. 1st of that month...
can any one help... ??? thnx in advanced
<%
Dim objRecordset
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "calendar", MM_mercury_STRING, adOpenStatic, adLockPessimistic, adCmdTable
%>
<%
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " & iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
Function GetWeekdayMonthStartsOn(iMonth, iYear)
GetWeekdayMonthStartsOn = WeekDay(CDate("1" & "/" & iMonth & "/" & iYear))
End Function
Function SubtractOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 1 Then
iMonth = 12
iYear = iYear - 1
Else
iMonth = iMonth - 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then
iDay = GetDaysInMonth(iMonth, iYear)
SubtractOneMonth = CDate(iDay & "-" & iMonth & "-" & iYear)
End Function
Function AddOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 12 Then
iMonth = 1
iYear = iYear + 1
Else
iMonth = iMonth + 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
AddOneMonth = CDate(iDay & "-" & iMonth & "-" & iYear)
End Function
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim iPosition ' Variable we use to hold current position in table
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
If IsDate(Request.QueryString("day") & "-" & Request.QueryString("month") & "-" & Request.QueryString("year")) Then
dDate = CDate(Request.QueryString("day") & "-" & Request.QueryString("month") & "-" & Request.QueryString("year"))
Else
dDate = Date()
If Request.QueryString.Count <> 0 Then
Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
End If
End If
End If
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(Month(dDate), Year(dDate))
%>
<% Response.buffer = "true" %>
<%
'-- Monthly Cycle Table --
If iDOW <> 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
iPosition = 1
Do While iPosition < iDOW
Response.Write(vbTab & vbTab & "<td class='CalNoDay'> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
End If
'-- Write days of month in proper day slots --
iCurrent = 1
iPosition = iDOW
Do While iCurrent <= iDIM
'-- open the table row --
If iPosition = 1 Then
Response.Write(vbTab & "<tr bgcolor=white>" & vbCrLf)
End If
'-- Write the date and subject --
Response.Write(vbTab & vbTab & "<td width=100 height=70 align=left valign=top class='CalDay'>" &_
" <a href='add_event.asp?Y=" & Year(dDate) & "&M=" & Month(dDate) & "&D=" & iCurrent & "' class='CalDayLink'>" & iCurrent & "</a><br>")
If Not objRecordset.BOF Then
objRecordset.MoveFirst
Do Until objRecordset.EOF
If objRecordset.Fields("Year") = Year(dDate) Then
If objRecordset.Fields("Month") = Month(dDate) Then
If objRecordset.Fields("Day") = iCurrent Then
Response.Write("<a class='CalEventLink' href='display_event.asp?ID=" & objRecordset.Fields("ID") & "'>" & objRecordset.Fields("Subject") & "</a><br>")
End If
End If
End If
objRecordset.MoveNext
Loop
End If
Response.Write("</td>" & vbCrLf)
'-- Close the table row --
If iPosition = 7 Then
Response.Write vbTab & "</tr>" & vbCrLf
iPosition = 0
End If
'-- Increment variables --
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write(vbTab & vbTab & "<td class='calNoDay'> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
Response.Write vbTab & "</tr>" & vbCrLf
End If
'-- End of Monthly cycle --
%>