Hej blir bara konstigare och konstigare...
Med nedanstående kod:
<%@ Language = VBSCRIPT %>
<% Option Explicit %>
<HTML>
<BODY>
<%
'Next, we need to obtain the current
'date. To do this, we will store the result of the
'Date() function into a variable named dbCurrentDate
Dim dbCurrentDate
dbCurrentDate = "4/1/2003"
'Now, we need to display a calendar. At most, a calendar
'can have six weeks. Since a week contains seven days,
'we will show, at most, 42 calendar cells. We will use
'a TABLE to generate this calendar
'We will create an array that will store the 42 possible
'days of the month.
Dim aCalendarDays(42)
'Into aCalendarDays, we will place the days of the current
'month. We will use the DatePart function to determine
'when the first day of the month is
Dim iFirstWeekday
iFirstWeekday = DatePart("w",DateSerial(Year(dbCurrentDate), Month(dbCurrentDate), 1))
'Now, we want to loop from 1 to the number of days in the
'current month, populating the array aCalendarDays
'Loopen gör ju att värdet: ( iLoop + iFirstWeekday - 1) ändras för varje varv
'loopen gör (iLoop räknas ju upp ett snäpp). Då blir det ju som så att först får då
'aCalendarDays(4) sitt värde, nästa varv får aCalendarDays(5) sitt värde osv.
'iLoop är ju själva räknaren som räknar upp, startar på 1, därav dras det sen bort -1
'alternativet borde ju kunna vara att börja räkna från 0 i stället.
'iFirstWeekday är ju med för att den inte ska börja räkna på första dagen i veckan, utan
'första dagen i månaden.
'iLoop = antalet dagar i aktuella månaden
Dim iDaysInMonth
iDaysInMonth = DatePart("d",DateSerial(Year(dbCurrentDate), Month(dbCurrentDate)+1, 1-1))
Dim iLoop
For iLoop = 1 to iDaysInMonth
aCalendarDays(iLoop + iFirstWeekday - 2) = iLoop
Next
'Now that we have our populated array, we need to display the
'array in calendar form. We will create a table of 7 columns,
'one for each day of the week. The number of rows we will use
'will be 6, the total number of possible rows, minus 42 (the upper
'bound of the aCalendarDays array) minus the last array position
'used (iFirstWeekday + iDaysInMonth) divided by seven, the number of
'days in the week! Simple, eh!! :)
Dim iColumns, iRows
iColumns = 7
iRows = 6 - Int((42 - (iFirstWeekDay + iDaysInMonth)) / 7)
'(iFirstWeekDay + iDaysInMonth) = totala antalet celler som behövs
'Now, create the table
%>
<TABLE ALIGN=CENTER BORDER=1 CELLSPACING=1 WIDTH=75% HEIGHT=75%>
<TH COLSPAN=7>
<FONT SIZE=+2>
<%
'Display the month and year
Response.Write GetMonthName(Month(dbCurrentDate))
Response.Write ", " & Year(dbCurrentDate)
%>
</FONT>
</TH>
<%
Response.Write "<TR><TD><CENTER><B>"
Response.Write "Måndag"
Response.Write "</B></CENTER></TD><TD><CENTER><B>"
Response.Write "Tisdag"
Response.Write "</B></CENTER></TD> <TD><CENTER><B>"
Response.Write "Onsdag"
Response.Write "</B></CENTER></TD><TD><CENTER><B>"
Response.Write "Torsdag"
Response.Write "</B></CENTER></TD><TD><CENTER><B>"
Response.Write "Fredag"
Response.Write "</B></CENTER></TD><TD><CENTER><B>"
Response.Write "Lördag"
Response.Write "</B></CENTER></TD><TD><CENTER><B>"
Response.Write "Söndag"
Response.Write "</B></CENTER></TD></TR>"
'Now, loop through 1 through iRows, then 1 through iColumns
Dim iRowsLoop, iColumnsLoop
For iRowsLoop = 1 to 6
'Create a new row
Response.Write "<TR>"
For iColumnsLoop = 1 to 7
'Create a new column
'If there is a day there, display it, else black out the cell
If aCalendarDays((iRowsLoop-1)*7 + iColumnsLoop)="" then
'Black out the cell
Response.Write "<TD BGCOLOR=BLACK> </TD>"
Else
'Display the date
Response.Write "<TD VALIGN=TOP ALIGN=RIGHT WIDTH=""14%"">"
Response.Write aCalendarDays((iRowsLoop-1)*7 + iColumnsLoop)
Response.Write "</TD>"
End If
Next
'Close the row
Response.Write "</TR>"
Next
%>
</TABLE>
</BODY>
</HTML>
Så fungerar det för:
april03
juli-03
januari-02 Men när jag kör för innevarande månad så blir det konstig. Som ni ser får jag inte med månadens första dag alls - som ju är en söndag .
Händer bara just juni -03 av alla de månader jag har provat!!
[3]Kan ngn av ER på detta forum please förklara varför?