---
title: "C Calendar 0.8"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/9128-c-calendar-0-8"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "cherub"
published: "2001-04-20T05:32:00.000Z"
updated: "2001-04-24T11:51:00.000Z"
replies: 6
views: 217
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/9128-c-calendar-0-8"
---

# C Calendar 0.8

## #1 — cherub, 2001-04-20T05:32Z

Det stod i reglerna när man skickade in script att man skulle skapa en tråd runt det. Så här kommer den. Tråden gäller scriptet:

<http://script.webforum.nu/wf/Forum1/HTML/000061.html>

Permalänk: https://www.webforum.nu/p/9128

## #2 — brw, 2001-04-20T06:20Z

Jag tror det är en bugg i kalendern.. skottår visas inte korrekt.. blir iaf. 28 dagar i februrari trots skottår.

Permalänk: https://www.webforum.nu/p/266943

## #3 — cherub, 2001-04-20T06:30Z

det har du rätt i... ;-) har fixat det nu.. så laddar du ner den igen är det fixat...

Permalänk: https://www.webforum.nu/p/266944

## #4 — andreas_lindh, 2001-04-23T14:57Z

Var ska jag ändra i koden så att varje dag blir länkad till en ny sida?

Permalänk: https://www.webforum.nu/p/266945

## #5 — cherub, 2001-04-23T15:38Z

Har inte scriptet här ju nu... Fick en HD-crash.... Men raden
Response.Write iDay 
Är den rad som skriver ut datumet...
Så där får du ändra... hur du vill ha det...

Permalänk: https://www.webforum.nu/p/266946

## #6 — nakoz, 2001-04-23T20:50Z

för er som e nyfikna så har jag mixat lite med kalendern å får allt å funka med databas å så nu iaf :)

här kommer koden som ni ska ersätta Response.Write iDay med.
först måste ni naturligtvis ha en databaskoppling:

```
Dim provider, ConnectionString, cn, rs, SQL
Set cn = Server.CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & Server.MapPath("events.mdb")
.Open
End With
```

den lägger ni förslagsvis högst upp i filen. databasen jag har nu heter events med tabellen dagbok som är uppbygd såhär:
year &#0124; Number
month &#0124; Number
day &#0124; Number
dagbok &#0124; Memo

sen kommer vi till själva koden då datumet skall göras till en länk, denna kan se ut som detta:

```
SQL = "SELECT * FROM dagbok WHERE [year] = "& iYear_ &" AND [month] = "& iMonth_ &" AND [day] = "& iDay
Set rs = cn.Execute(SQL)

If rs.EOF Then
Response.Write iDay
Else
Response.Write "<a href='dagbok.asp?ar="& iYear_ &"&man="& iMonth_ &"&day="& iDay &"'>"& iDay &"</a>"
End If
```

ersätt alltså Response.Write iDay med koden ovan, så bör allt funka som ni vill. å glöm inte å ändra dagbok.asp till den sidan ni vill.. :) 

mvh

Permalänk: https://www.webforum.nu/p/266947

## #7 — jispir, 2001-04-24T11:51Z

varför får jag inte dagensdatum markerat?
Jag har ändrat koden så som nakoz skrev!

koden ser ut så här:

```

Dim provider, ConnectionString, cn, rs, SQL
Set cn = Server.CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & Server.MapPath("events.mdb")
.Open
End With 

Class cCalendar

Private iMonth_				'** Current month 	&#0124; Default: This month
Private iYear_				'** Current year 	&#0124; Default: This year

	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Constructor
	'** Sets some values to default
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	Public Sub Class_Initialize()

		iYear_ = Year(date())
		iMonth_ = Month(date())

	End Sub
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Returns the number of days in specified month
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	Private Function DaysInMonth()
	
	'** Declare Variables
		Dim iDaysInMonth
				
		Select Case iMonth_
			Case 1, 3, 5, 7, 8, 10, 12 	'** Months with 31 days
				iDaysInMonth = 31
			Case 4, 6, 9, 11 			'** Months with 30 days
				iDaysInMonth = 30 
			Case 2 						'** Check february if it's leap year or not
				If IsDate(iYear_ & "-02-29") Then
					iDaysInMonth = 29
				Else
					iDaysInMonth = 28
				End If
		End Select
		
	DaysInMonth = iDaysInMonth

	End Function
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Returns the number of day that the first day in the month has
	'** 1 = Monday, 7 = Sunday
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>	
	Private Function StartWeekday()
	
		'** Weekday() returns by default 1 = Sunday and 7 = Saturday
		'** but we want Monday to be 1 and sunday to be 7
		'** there for this function.
		
		'** Declare Variables
			Dim dtMonthdate, iStartWeekday
		
		dtMonthdate = iYear_ & "-" & iMonth_ & "-01"	
		iStartWeekday = Weekday(dtMonthdate)
	
			If iStartWeekday > 1 Then 
				iStartWeekday = iStartWeekday - 1
			
			Else
				iStartWeekday = iStartWeekday + 6
			
			End If 
			
	StartWeekday = iStartWeekday
	
	End Function
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Returns how many rows the calendar will contain
	'** One row = 7 days (Monday to Sunday)
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	Private Function TableRows(iDaysInMonth, iStartWeekday)
		Dim iBoxes, iTblRows
		
		iBoxes = (iDaysInMonth + (iStartWeekday - 1))
	
			If iBoxes = 28 Or iBoxes = 35 Or iBoxes = 42 Then
				iTblRows = iBoxes / 7

			ElseIf iBoxes > 28 And iBoxes < 35 Then
				iTblRows = 5

			Else
				iTblRows = 6

			End If
		
		TableRows = iTblRows
			
	End Function
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Return values one month forward and backward
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>	
	Private Sub SetBackwardAndForwardValues (ByRef iMonthBackward, ByRef iMonthForward, _
											 ByRef iYearBackward, ByRef iYearForward)
		Select Case iMonth_
			Case 12
				iMonthForward = 1
				iMonthBackward = 11
				iYearForward = iYear_ + 1
				iYearBackward = iYear_
			Case 1
				iMonthForward = 2
				iMonthBackward = 12
				iYearForward = iYear_
				iYearBackward = iYear_ - 1
			Case Else
				iMonthForward = iMonth_ + 1
				iMonthBackward = iMonth_ - 1
				iYearForward = iYear_
				iYearBackward = iYear_
		End Select
						
	End Sub	
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Draw the calendar
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	Public Sub GetCalendar(iMonth, iYear, sThisPage, sBorderColor)
	
	'** GetValues
		If Not iMonth = "" Then iMonth_ = iMonth 	'** Get Month
		If Not iYear = "" Then iYear_ = iYear 		'** Get Year
	
		

		'** Table for calendar
			Response.Write "<table cellspacing=""0"" cellpadding=""0"" border=""0"" width=""25%"">"
			
			'** First row
				Response.Write "<tr>"
				    Response.Write "<td height=""3"" colspan=""15"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
				Response.Write "</tr>"
				
				Response.Write "<tr>"
					Response.Write "<td width=""3"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
				    Response.Write "<td colspan=""13"">"
					
					'** HEAD: Displays month and year + arrows that allows you to go backward and forward
						Response.Write "<table cellspacing=""0"" cellpadding=""0"" border=""0"" width=""100%"">"
							Response.Write "<tr>"
								Response.Write "<td width=""75%"" align=""left"" class=""Size11Blue"">"
									
								'** Declare variables
									Dim sMonthName
									
								'** The MonthName() function returns the name in lowercase and we want the first letter to be uppercase
									sMonthName = UCase(Left(MonthName(iMonth_),1)) & Right(MonthName(iMonth_),Len(MonthName(iMonth_))-1) 
									Response.Write sMonthName & ", " & iYear_
								
								Response.Write "</td>"
								
							'** Declare variables
								Dim iMonthForward, iMonthBackward, iYearForward, iYearBackward
							
							'** Return values one month forward and backward
								Call SetBackwardAndForwardValues (iMonthBackward, iMonthForward, iYearBackward, iYearForward)
	
								Response.Write "<td width=""25%"" align=""center"">"
									
									'** Arrows that allows you to go backward and forward
										Response.Write "<a href=""" & sThisPage & "?iMonth=" & iMonthBackward & "&iYear=" & iYearBackward & """><img src=""arrow_left.gif"" width=""10"" height=""10"" border=""0""></a>"
										Response.Write "&nbsp;&nbsp;"
										Response.Write "<a href=""" & sThisPage & "?iMonth=" & iMonthForward & "&iYear=" & iYearForward & """><img src=""arrow_right.gif"" width=""10"" height=""10"" border=""0""></a>"
										
								Response.Write "</td>"
							Response.Write "</tr>"
						Response.Write "</table>"
					'** END HEAD
				
					Response.Write "</td>"
					Response.Write "<td width=""3"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
				Response.Write "</tr>"
									
				Response.Write "<tr>"
				    Response.Write "<td height=""3"" colspan=""15"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
				Response.Write "</tr>"
				
			'** Displays the days to the calendar Monday - Sunday
				Response.Write "<tr>"
					
					Response.Write "<td width=""3"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
				
				'** Declare variables
					Dim i, sWeekdayName
				
				'** Loop for each day in a week Monday - Sunday
					For i = 1 to 7
						
						'** WeekdayName() returns the name in lowercase. We want the first letter to be uppercase and the rest lowercase
						sWeekdayName = Ucase(Left(WeekdayName(i, True, 2), 1)) & Right(WeekdayName(i, True, 2), Len(WeekdayName(i, True, 2)) - 1)
						
						Response.Write "<td align=""center"" valign=""center"" class=""Size11DarkGray"">" & sWeekdayName & "</td>"
						Response.Write "<td width=""3"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"								
		
					Next
					
				Response.Write "</tr>"
		
				Response.Write "<tr>"
				    Response.Write "<td height=""3"" colspan=""15"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
				Response.Write "</tr>"
				
			'** Declare variables
				Dim iCount, iDay, iDaycount, iDaysInMonth, iStartWeekday, iTableRows
				Dim bFirstrow
				
			'** Set values
				iDaysInMonth = DaysInMonth() 	'** Returns how many days there is in the current month
				iStartWeekday = StartWeekday()	'** Returns which day the month starts on (1-7)
				iTableRows = TableRows(iDaysInMonth, iStartWeekday) '** Returns how many rows the table will be
				
			'** Initialize
				iCount = 0 : iDay = 1 : bFirstRow = True
			
				Do While iTableRows > iCount '** This will go round
				
					Response.Write "<tr>" '** Start row
					
					For iDaycount = 1 to 7 '** Loop to make 7 squares for 1 row
							
							If iDaycount = 1 Then Response.Write "<td width=""3"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
							
								If ((bFirstrow = True) And (iDaycount < iStartWeekday)) Or (iDay > iDaysInMonth) Then '** This day does not exist in the month. Could be mars and iDay is 34
		
									Response.Write "<td align=""center"" valign=""center""><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
							
								ElseIf (iDay <= iDaysInMonth) Then '** Is iDay a day that exists in this month
								
									Response.Write "<td align=""center"" valign=""center"" class=""Size11DarkGray"">"
								
									'** Display day number
										SQL = "SELECT * FROM events WHERE [year] = "& iYear_ &" AND [month] = "& iMonth_ &" AND [day] = "& iDay
										Set rs = cn.Execute(SQL)
										If rs.EOF Then
										Response.Write iDay
										Else
										Response.Write "<a href='dagbok.asp?ar="& iYear_ &"&man="& iMonth_ &"&day="& iDay &"'>"& iDay &"</a>"
										End If

								
									Response.Write "</td>"
				
								End If
						
							Response.Write "<td width=""3"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"							
		
						
						If Not ((bFirstrow = True) And (iDaycount < iStartWeekday)) Then 
							iDay = iDay + 1
						ElseIf (bFirstrow = True) And (iDaycount >= iStartWeekday) Then
							iDay = iDay + 1 '** Add one to iDay and check that Day for posts
						End If
						
					Next
						
					Response.Write "</tr>"
		
				'** Last row
					Response.Write "<tr>"
				    	Response.Write "<td height=""3"" colspan=""15"" bgcolor=""" & sBorderColor & """><img src=""1x1.gif"" width=""1"" height=""1"" border=""0""></td>"
					Response.Write "</tr>"
				
				bFirstrow = False
				iCount = iCount + 1 '** Add one to count and show next 7 days
		
				Loop
				
			Response.Write "</table>"

	End Sub
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	'** Destructor
	'** Clean up
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>
	Public Sub Class_Terminate()

	End Sub	

End Class

		
Dim objCalendar		
Set objCalendar = New cCalendar
	
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	'** Inputvalues
	'** => iMonth 		&#0124; Pics up the QueryString iMonth. If it's empty this will be month this day
	'** => iYear		&#0124; Pics up the QueryString iYear. If it's empty this will be the year this day
	'** => sThis Page	&#0124; What page to send to when pushing forward or backward button
	'** => sBorderColor &#0124; What color to be used on the border
	'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&gt ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	objCalendar.GetCalendar Request.QueryString("iMonth"), Request.QueryString("iYear"), "/calendar/calendar.asp","#f5f5f5"

Set objCalendar = Nothing
```

Permalänk: https://www.webforum.nu/p/266948

---

Tråden på webben: https://www.webforum.nu/amne/asp/9128-c-calendar-0-8
