VB icon

Complete ASP Calendar

Email
Submitted on: 1/5/2015 3:08:00 PM
By: Matt Pantana (from psc cd)  
Level: Intermediate
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 1074
 
     Displays a dynamic calendar in html using asp

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :Complete ASP Calendar
'**************************************
none: distribute freely
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Complete ASP Calendar
' Description:Displays a dynamic calendar in html using asp
' By: Matt Pantana (from psc cd)
'
' Inputs:You can input the month or the year, but neither is required
'
' Returns:a calendar
'
' Assumes:Just copy and paste the whole thing
'**************************************

<%
response.expires=0
dim CurMonth
dim CurDay
dim CurYear
dim NumOfDays
dim CurCell
dim onDay
dim FoundFirst
CurMonth = request.querystring("cmonth")
CurYear = request.querystring("cyear")
CurDay = request.querystring("cday")
if CurMonth = "" then curMonth = month(date)
if CurYear = "" then CurYear = year(date)
if CurDay = "" then CurDay = day(date)
FirstDay = weekday(CurMonth & "/01/" & CurYear)
cmonth = CurMonth
cyear = CurYear
NumOfDays = getlastday(cmonth,cyear)
FoundFirst = false
curcell = 1
onDay = 0
 function GetLastDay( tmonth, tyear )
 tmonth = tmonth + 1
 if tmonth > 12 Then
 tmonth = tmonth - 12
 tyear = tyear + 1
 End if
 Dim x
 x = DateAdd("d", -1, tmonth & "/01/" & tyear)
 GetLastDay = Day( x )
 End function
 
rows = 5
if firstday >= 5 and numofdays = 31 then
 rows = 6
end if
if firstday >= 6 and numofdays = 30 then
 rows = 6
end if
 
 function DayOf()
 if foundFirst then
	 onDay = OnDay + 1
	 if onDay > NumofDays then
	 DayOf = ""
	 else
	 DayOf = onDay
	 end if
	 
	else
	 if curcell = Firstday or firstday = 1 then foundfirst = true
	 
	 if foundFirst then
	 onDay = OnDay + 1
		if onDay > NumofDays then
		DayOf = ""
	
		else
		DayOf = onDay
		
	 end if
	 else
	 DayOf = ""
	 end if
	 
	end if
curcell = curcell + 1
	 if (OnDay + 1) = int(CurDay) and int(CurMonth) = int(month(date)) and int(CurYear) = year(date) then 
	 bgcolor = "yellow"
	 else
	 bgcolor = ""
	 end if
 end function
%>
<html>
<head>
<title>Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<script language="VBScript">
Sub cmonth_onchange
frm.submit
end sub
Sub cyear_onchange
frm.submit
end sub
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="350" border="0" cellspacing="0" cellpadding="0">
 <form name=frm method=get action=calendar.asp>
 <tr> 
<td width="37"> </td>
<td width="137"> </td>
<td width="144"> </td>
<td width="32"> </td>
 </tr>
 <tr> 
<td width="37"> </td>
<td width="137"> 
<select name="cmonth">
 <% for i = 1 to 12 %>
 <option value="<%=i%>" <%if int(curmonth) = i then response.write("Selected")%>><%=monthname(i)%></option>
 <% next %>
</select>
</td>
<td width="144"> 
<select name="cyear">
 <% for i = 2050 to 1980 step -1 %>
 <option value="<%=i%>" <%if int(curyear) = i then response.write("Selected")%>><%=i%></option>
 <% next %>
</select>
</td>
<td width="32"> </td>
 </tr>
 <tr> 
<td width="37"> </td>
<td width="137"> </td>
<td width="144"> </td>
<td width="32"> </td>
 </tr>
 </form>
</table>
<table width="350" border="0" cellspacing="0" cellpadding="0">
 <tr bgcolor="#666666"> 
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">S</font></b></font></div>
 </td>
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">M</font></b></font></div>
 </td>
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">T</font></b></font></div>
 </td>
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">W</font></b></font></div>
 </td>
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">T</font></b></font></div>
 </td>
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">F</font></b></font></div>
 </td>
 <td> 
<div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">S</font></b></font></div>
 </td>
 </tr>
 <% for i = 1 to rows %>
 <tr> 
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 <td bgcolor="<%=bgcolor%>"> 
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%=DayOf%></font></div>
 </td>
 </tr>
 <% next %>
</table>
</body>
</html>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.