% class ASP_Calendar private p_chooser ' If the calendar will be used to select a date for a form private p_db_bind ' If the calendar will be databound by a database connection private p_db_conn ' A connection to a database private p_db_field ' The string name of the database field containing the calendar dates private p_db_table ' The string name of the database table containing the calendar dates private p_month ' The month to display private p_url ' The url to link to ' 1) the same page on which the calendar is displayed when scrollable is on ' 2) the page to link to when scrollable is off private p_year ' The year to display private p_selectable private p_scrollable ' If the calendar is scrollable links exist to change the month, otherwise the ' name of the month is a link to p_url and no scroll buttons are displayed private sub Class_Initialize() ' Initialize property values p_db_bind = false p_db_field = "" p_db_table = "" p_month = month(date()) p_year = year(date()) p_selectable = false p_scrollable = false end sub ' Draw method outputs html to the browser to display the calendar and dates public function draw(a_url) dim dates dates = "|" if p_db_bind then dim rs dim sql sql = "SELECT DISTINCT " & p_db_field & " FROM " & p_db_table & _ " WHERE MONTH(" & p_db_field & ") = '" & p_month & "' AND " & _ " YEAR(" & p_db_field & ") = '" & p_year & "'" p_db_conn.open() set rs = p_db_conn.execute(sql) while not rs.eof dates = dates & day(rs.fields(p_db_field)) & "|" rs.movenext wend p_db_conn.close() end if ' Exits the method if the month and year are not numeric or the month is out of range if not isnumeric(p_month) or not isnumeric(p_year) or p_month < 1 or p_month > 12 then response.Write "There was an error displaying the days for month number " & p_month & _ " for the year " & p_year exit function end if ' Exits the method if the requested month has passed if p_year < Year(Date()) then p_year = Year(Date) end if ' Exits the method if the requested month has passed if p_year = Year(Date()) and p_month < Month(Date()) then p_year = Year(Date) p_month = Month(Date) end if ' Assign url to calendar p_url = a_url ' Dimension variables dim cursor dim output dim row ' Initialize cursor to 1 cursor = 1 ' Initialize output string with calendar header output = "
" dim current_date current_date = DateSerial(p_year, p_month, cursor) ' Display the corrrect date for the day of the week if IsDate(current_date) and WeekDay(current_date) = col and Month(current_date) = p_month then dim cursor_output cursor_output = cursor if dates <> "|" and instr(dates, "|" & cursor & "|") > 0 then cursor_output = "" & cursor & "" end if output = output & cursor_output cursor = cursor + 1 end if output = output & " | " next output = output & "