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!

Event Calendar Problem

Status
Not open for further replies.

skendrick

Technical User
Mar 31, 2003
34
0
0
Hello,

I am trying to use this calendar code I found on Asp101.com to mark out the days that have an event on them, right now the code will gray out the current day. I want it to gray out the days that have an event. It will get the dates from a MS SQL Database. The format of the table that holds the date has two columns “eventStart” and “eventEnd” So if it has an eventStart of 2/12/2005 and an eventEnd of 2/18/2005 it will gray out all of the days from 2/12/2005 – 2/18/2005 I hope this makes sense, and sorry for coping the long code. The code below is almost how it was when I started except for the different colors for the calendar. I have tried for almost 3 weeks to figure this out. I have been successful in writing a red X for the days that need to be gray, but just can’t figure out how to get it to gray the dates (the red x isn’t in this current code).

Thanks in advance,
Sterling

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Function GetDaysInMonth(iMonth, iYear)
	Dim dTemp
	dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
	GetDaysInMonth = Day(dTemp)
End Function

Function GetWeekdayMonthStartsOn(dAnyDayInTheMonth)
	Dim dTemp
	dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
	GetWeekdayMonthStartsOn = WeekDay(dTemp)
End Function

Function SubtractOneMonth(dDate)
	SubtractOneMonth = DateAdd("m", -1, dDate)
End Function

Function AddOneMonth(dDate)
	AddOneMonth = DateAdd("m", 1, dDate)
End Function
' ***End Function Declaration***


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


' Get selected date.  There are two ways to do this.
' First check if we were passed a full date in RQS("date").
' If so use it, if not look for seperate variables, putting them togeter into a date.
' Lastly check if the date is valid...if not use today
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()
		' The annoyingly bad solution for those of you running IIS3
		If Len(Request.QueryString("day")) <> 0 Or Len(Request.QueryString("month")) <> 0 Or Len(Request.QueryString("year")) <> 0 Or Len(Request.QueryString("date")) <> 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
		' The elegant solution for those of you running IIS4
		'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

'Now we've got the date.  Now get Days in the choosen month and the day of the week it starts on.
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(dDate)
%>
<html>
<head>
<title>Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<TABLE width="143" BORDER=0 CELLPADDING=1 CELLSPACING=0 bordercolor="#000000" BGCOLOR=#99CC66>
	<TR>
		<TD COLSPAN=7 ALIGN="center" BGCOLOR=#000099>
			<TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0 bgcolor="#006666">
				<TR>
					<TD ALIGN="right"><font face="Arial, Helvetica, sans-serif"><A HREF="./calendar.asp?date=<%= SubtractOneMonth(dDate) %>"><FONT COLOR=#FFFFFF SIZE="2">&lt;&lt;</FONT></A></font></TD>
					<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B><%= MonthName(Month(dDate)) & "  " & Year(dDate) %></B></FONT></TD>
					<TD ALIGN="left"><font face="Arial, Helvetica, sans-serif"><A HREF="./calendar.asp?date=<%= AddOneMonth(dDate) %>"><FONT COLOR=#FFFFFF SIZE="2">&gt;&gt;</FONT></A></font></TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
	<TR>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>S</B></FONT></TD>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>M</B></FONT></TD>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>T</B></FONT></TD>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>W</B></FONT></TD>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>T</B></FONT></TD>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>F</B></FONT></TD>
		<TD ALIGN="center"><FONT COLOR=#FFFFFF size="2" face="Arial, Helvetica, sans-serif"><B>S</B></FONT></TD>
	</TR>
<%
' Write spacer cells at beginning of first row if month doesn't start on a Sunday.
If iDOW <> 1 Then
	Response.Write vbTab & "<TR>" & vbCrLf
	iPosition = 1
	Do While iPosition < iDOW
		Response.Write vbTab & vbTab & "<TD BGCOLOR=#006666></TD>" & vbCrLf
		iPosition = iPosition + 1
	Loop
End If
' Write days of month in proper day slots
iCurrent = 1
iPosition = iDOW

Do While iCurrent <= iDIM
	' If we're at the begginning of a row then write TR
	If iPosition = 1 Then
		Response.Write vbTab & "<TR>" & vbCrLf
	End If
	
	' If the day we're writing is the selected day then highlight it somehow.
	If iCurrent = Day(dDate) AND Month(dDate) = Month(now) Then
		Response.Write vbTab & vbTab & "<TD ALIGN=center BGCOLOR=#CCCCC><A HREF=""./calendar.asp?date=" & Month(dDate) & "/" & iCurrent & "/" & Year(dDate) & """><FONT COLOR=#FFFFFF SIZE=2>" & iCurrent & "</FONT></A></TD>" & vbCrLf
	Else
		Response.Write vbTab & vbTab & "<TD ALIGN=center><A HREF=""./calendar.asp?date=" & Month(dDate) & "/" & iCurrent & "/" & Year(dDate) & """><FONT COLOR=#FFFFFF SIZE=2>" & iCurrent & "</FONT></A></TD>" & vbCrLf
	End If

	' If we're at the endof a row then write /TR
	If iPosition = 7 Then
		Response.Write vbTab & "</TR>" & vbCrLf
		iPosition = 0
	End If
	
	' Increment variables
	iCurrent = iCurrent + 1
	iPosition = iPosition + 1

Loop
' Write spacer cells at end of last row if month doesn't end on a Saturday.
If iPosition <> 1 Then
	Do While iPosition <= 7
		Response.Write vbTab & vbTab & "<TD BGCOLOR=#006666></TD>" & vbCrLf
		iPosition = iPosition + 1
	Loop
	Response.Write vbTab & "</TR>" & vbCrLf
End If
%>
</TABLE>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top