Serious help needed - Calendar!

Discussion in 'ASP General' started by William (Tamarside), Jul 28, 2008.

  1. Please, if you have the time and knowledge to help me I'd truly
    appreciate it!
    I need to build a calendar page that displays available/unavailable
    info from a DB and colour a cell according to that info, but somewhere
    I've gone completely off the rails! Basically it is a room
    availability page for an intranet and should simply colour a calendar
    cell red if the room is booked, or green if it isn't. Rooms are
    typically booked by lecturers for multiple days or even weeks, so only
    the start and end dates are entered into the calendar.
    My code doesn't get all the info and I'm pulling hair out with
    frustration!

    Anyway, here's the code:

    <!--#include file = "datacon.asp"-->
    <%CODEPAGE="1252"
    Dim MyMonth 'Month of calendar
    Dim MyYear 'Year of calendar
    Dim FirstDay 'First day of the month. 0 = Sunday
    Dim CurrentDay 'Used to print dates in calendar - Day only, otherwise
    same as varDateNow
    Dim Col 'Calendar column
    Dim Row 'Calendar row

    '======
    Dim RoomCI 'Start booking
    Dim RoomCO 'End booking

    Dim varBackground 'cell background colour
    Dim varDateNow 'Current full date ---> Not actual date, but date
    calendar cell is working with


    Dim var1stBack


    MyMonth = cint(Request.Querystring("Month"))
    MyYear = cint(Request.Querystring("Year"))

    If MyMonth = 0 then MyMonth = Month(Date)
    if MyYear = 0 then MyYear = Year(Date)

    Call ShowHeader (MyMonth, MyYear)

    FirstDay = WeekDay(DateSerial(MyYear, MyMonth, 1)) -1
    CurrentDay =
    1 '--------------------------------------------------------------------------------
    >Start CurrentDay on 1

    '=================================
    varDateNow = Trim(Currentday) & "/" & Trim(MyMonth) & "/" &
    Trim(MyYear)
    varDateNow = CDate(varDateNow)
    '=================================
    Dim var1stDay
    var1stDay = "01" & "/" & Trim(MyMonth) & "/" & Trim(MyYear) 'We need
    to start looking at the 1st of the month
    var1stDay=CDate(var1stDay) 'Change the variable to a proper date



    'Let's build the calendar
    dim varCDay
    varBackground = "green" 'Default starting background colour
    For Row = 0 to 5
    rscal = ""
    rsCal1 = ""
    For Col = 0 to 6
    If Row = 0 and Col < FirstDay then

    response.write "<td>&nbsp;</td>"
    elseif CurrentDay > LastDay(MyMonth, MyYear) then
    response.write "<td>&nbsp;</td>"
    else

    '========================================================
    'This section formats varDateNow
    Dim varCurrentDay 'CurrentDay reformatted to always have 2 char's
    Dim TotalDays
    Dim TotalDate
    Dim HouseName

    '=====================================
    If CurrentDay < 10 and MyMonth >= 10 then varDateNow = "0" &
    Trim(Currentday) & "/" & Trim(MyMonth) & "/" & Trim(MyYear)
    If CurrentDay < 10 and MyMonth < 10 then varDateNow = "0" &
    Trim(Currentday) & "/" & "0" & Trim(MyMonth) & "/" & Trim(MyYear)
    If CurrentDay => 10 and MyMonth < 10 then varDateNow =
    Trim(Currentday) & "/" & "0" & Trim(MyMonth) & "/" & Trim(MyYear)
    If CurrentDay >= 10 and MyMonth >=10 then varDateNow =
    Trim(Currentday) & "/" & Trim(MyMonth) & "/" & Trim(MyYear)
    'If CurrentDay < 10 then CurrentDay = "0" & CurrentDay
    varDateNow = CDATE(VarDateNow)


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'response.write "varDateNow = " & varDateNow & "<br>"
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    set rsCal = cnndata.Execute("SELECT codate, cidate FROM tblReservation
    WHERE cidate >= '" & varDateNow & "' AND room ='ICT-01'")
    If Not rsCal.EOF then RoomCI = rscal("cidate")
    If Not rsCal.EOF then RoomCO = rscal("codate")
    RoomCI = CDATE(RoomCI)
    RoomCO = CDATE(RoomCO)
    varDateNow = CDATE(varDateNow)

    If RoomCO = varDateNow AND RoomCI < varDateNow THEN varBackground =
    "green"
    If RoomCI = varDateNow then varBackground = "red"

    If Not rsCal.EOF then RoomCI = rscal("cidate")

    RoomCI = CDATE(RoomCI)
    RoomCO = CDATE(RoomCO)

    If Not rsCal.EOF then rsCal.MoveNext

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''







    '================================================

    response.write "<td bgcolor='" & varBackground & "'"

    if MyMonth = Month(Date) and CurrentDay = Day(Date) then
    response.write " align='center'>"
    else
    response.write " align='center'>"
    end if


    'Print the day date number and bold on selected date

    if request("selecteddate") = "" Then
    if CurrentDay = day(date) Then
    response.write "" & CurrentDay & ""
    else
    response.write "<font=Arial>" & CurrentDay & "</font>" 'This is
    the line that writes the days to the calendar
    end if
    else
    if day(request("selecteddate")) = CurrentDay Then
    response.write "" & "<font=Arial>" & CurrentDay & "</font>" & ""
    else
    response.write CurrentDay
    end if

    end if

    response.write "</a></td>"

    CurrentDay = CurrentDay + 1

    End If

    Next
    response.write "</tr>"
    Next


    response.write "</table>"



    '------ Sub and functions


    Sub ShowHeader(MyMonth,MyYear)
    %>
    <body>


    <table cellspacing='1' cellpadding='0' width='35%' border="1"
    bordercolor="#800000">
    <tr align='center'>
    <td colspan='7'>
    <table border='0' width='100%'>
    <tr>
    <td align='left'>

    <font face="Tahoma" color="black">

    <%
    response.write "<font face='Tahoma' color='black'><a href = '" &
    Request.ServerVariables("SCRIPT_NAME") & "?"
    if MyMonth - 1 = 0 then
    response.write "month=12&year=" & MyYear -1
    else
    response.write "month=" & MyMonth - 1 & "&year=" & MyYear
    end if
    response.write "'><<</a>"
    %>

    </font>

    </td><td align='center' class='ListHeaderTable'>

    <%
    response.write "<b><font face='Tahoma' color='black'>" &
    MonthName(MyMonth) & " " & MyYear & "</font></b>"
    %>

    </font>

    </td><td align='right'>


    <%
    response.write "<font face='Tahoma' color='black'><a href = '" &
    Request.ServerVariables("SCRIPT_NAME") & "?"
    if MyMonth + 1 = 13 then
    response.write "month=1&year=" & MyYear + 1
    else
    response.write "month=" & MyMonth + 1 & "&year=" & MyYear

    end if
    response.write "'>>></a>"
    %>

    </font>

    </td></tr></table>
    </td>
    </tr>
    <tr align='center'>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Sun</i></
    b></font></td>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Mon</i></
    b></font></td>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Tue</i></
    b></font></td>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Wed</i></
    b></font></td>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Thu</i></
    b></font></td>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Fri</i></
    b></font></td>
    <td width="8%" ><font color="#800000" face="Tahoma"><b><i>Sat</i></
    b></font></td>
    </tr>


    </body>

    <%
    End Sub

    Function MonthName(MyMonth)
    Select Case MyMonth
    Case 1
    MonthName = "January"
    Case 2
    MonthName = "Febuary"
    Case 3
    MonthName = "March"
    Case 4
    MonthName = "April"
    Case 5
    MonthName = "May"
    Case 6
    MonthName = "June"
    Case 7
    MonthName = "July"
    Case 8
    MonthName = "August"
    Case 9
    MonthName = "September"
    Case 10
    MonthName = "October"
    Case 11
    MonthName = "November"
    Case 12
    MonthName = "December"
    Case Else
    MonthName = "ERROR! - Monthname"
    End Select
    End Function

    Function LastDay(MyMonth, MyYear)
    ' Returns the last day of the month. Takes into account leap years
    ' Usage: LastDay(Month, Year)
    ' Example: LastDay(12,2000) or LastDay(12) or Lastday


    Select Case MyMonth
    Case 1, 3, 5, 7, 8, 10, 12
    LastDay = 31

    Case 4, 6, 9, 11
    LastDay = 30

    Case 2
    If IsDate(MyYear & "-" & MyMonth & "-" & "29") Then
    LastDay = 29 Else LastDay = 28

    Case Else
    LastDay = 0

    End Select
    End Function
    %>
    William (Tamarside), Jul 28, 2008
    #1
    1. Advertising

  2. William (Tamarside)

    Old Pedant Guest

    "William (Tamarside)" wrote:

    > I need to build a calendar page that displays available/unavailable
    > info from a DB and colour a cell according to that info, but somewhere
    > I've gone completely off the rails!


    Well, I recognize some of the very very crappy code in there. It's from an
    ANCIENT article on one of the sites (I forget which one). Just for instance,
    all that crap to get the MonthName is *BUILT IN* to VBScript! I *think* in
    verion 1.0 it was not, and if that's the reason, then that code dates to 1998
    or maybe even 1997.

    I have what I think is a much simpler and cleaner and easier to understand
    Calendar. It's not ideal for your usage, because it was designed to handle
    multiple events on each date. But it could be easily adapted, I would think.

    You can find it at
    http://www.ClearviewDesign.com/Newbie
    Look in the DEMOS for the "Calendar of Events".

    You'll see that the "trick" to it is creating a simple list of all possible
    dates in the DB, first, and then it's easy to add multiple events that span
    any number of days and can only use certain days of the week and and and.
    The data entry is left as an exercise to the reader, but at least the
    calendar is simple to use.
    Old Pedant, Jul 29, 2008
    #2
    1. Advertising

  3. William (Tamarside)

    Evertjan. Guest

    William (Tamarside) wrote on 29 jul 2008 in
    microsoft.public.inetserver.asp.general:

    > Function MonthName(MyMonth)
    > Select Case MyMonth
    > Case 1
    > MonthName = "January"
    > Case 2
    > MonthName = "Febuary"
    > Case 3
    > MonthName = "March"
    > Case 4
    > MonthName = "April"
    > Case 5
    > MonthName = "May"
    > Case 6
    > MonthName = "June"
    > Case 7
    > MonthName = "July"
    > Case 8
    > MonthName = "August"
    > Case 9
    > MonthName = "September"
    > Case 10
    > MonthName = "October"
    > Case 11
    > MonthName = "November"
    > Case 12
    > MonthName = "December"
    > Case Else
    > MonthName = "ERROR! - Monthname"
    > End Select
    > End Function
    >


    For the English, this function is build-in in VBS:
    MonthName(month[, abbreviate]),
    so even the function assignment will error,
    as the name is reserved.

    For other languages or more flexibility
    your code is simply silly in it's size,
    and testing for errors by just returning errortext is not very useful,
    try using a simple array:

    myMonthName = Array("?","January","Febuary","March",_
    "April","May","June","July","August",_
    "September","October","November","December")

    The rest of you code is also not worth much.

    A simple remedy is never to use code that
    you do not understand,
    you did not thoroughly test yourself in small modules,
    that is not pleasing to you in it's elegance and logic.

    Just copying code in the hope it will work,
    and work in your context, that the original programmer did not know,
    or is written for an ancient version of VBS,
    will get you into the troubles you have.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jul 29, 2008
    #3
  4. On 29 Jul, 08:01, "Evertjan." <> wrote:
    > The rest of you code is also not worth much.
    >
    > A simple remedy is never to use code that
    > you do not understand,
    > you did not thoroughly test yourself in small modules,
    > that is not pleasing to you in it's elegance and logic.
    >
    > Just copying code in the hope it will work,
    > and work in your context, that the original programmer did not know,
    > or is written for an ancient version of VBS,
    > will get you into the troubles you have.



    Well thank you so much for absolutely nothing! And here I thought
    Google Groups was a community where one could ask others for help.
    Silly me!
    A couple of points, though:
    1) There is a huge difference between "don't understand" and "use code
    that works and has been posted on the Net, because it's quicker"
    2) The entire calendar works and works well, regardless of what you or
    I may think of the coding standards.
    3) The problem I have is with the SQL query, as I don't get all the
    dates where I know there are bookings.
    4) Next time you intend to be a smart-arse, try writing code in VB.Net
    to allow for integration between Active Directory, Exchange, MOSS07
    and two 3rd party apps.
    5) Being nice to people costs nothing, so when people ask for help,
    either offer help or stay quiet. Admittedly being a jerk on here is
    free, too.
    William (Tamarside), Jul 29, 2008
    #4
  5. William (Tamarside)

    Old Pedant Guest

    "Evertjan." wrote:

    > For the English, this function is build-in in VBS:
    > MonthName(month[, abbreviate]),
    > so even the function assignment will error,
    > as the name is reserved.
    >
    > For other languages or more flexibility
    > your code is simply silly in it's size,


    Ummm...For *all* languages, the MonthName function is builtin. You just
    have to set the correct locale via Session.LCID.

    Here is code that demonstrates this for at least some of the more common
    locales:

    **** LCIDDemo.asp ******
    <TABLE Border=1 Cellpadding=3>
    <TR>
    <TH>LCID</TH>
    <TH>MonthName(12)</th>
    <TH>unformatted<br>date</TH>
    <TH>formatted<br>date</th>
    <TH>formatted<br>number</th>
    <TH>formatted<br>currency</TH>
    </TR>
    <%
    when = Now() ' just to get a handy datetime value
    amount = 12345.6789 ' an a handy number

    saveLCID = Session.LCID ' so we can reset to this at end

    For lcid = &H0401 TO &H0FFF ' 401 is smallest LCID, but FFF is not largest
    On Error Resume Next
    Session.LCID = lcid ' this will fail if the LCID isn't supported on
    your machine
    On Error GoTo 0
    If Session.LCID = lcid Then ' so only show LCIDs that work
    %>
    <TR>
    <TD><%=lcid%> (0x<%=Hex(lcid)%>)</TD>
    <TD><%=MonthName(12)%></TD>
    <TD><%=when%></TD>
    <td><%=FormatDateTime(when,vbLongDate)%></TD>
    <TD><%=FormatNumber(amount,2)%></TD>
    <TD><%=FormatCurrency(amount)%></TD>
    </TR>
    <%
    End If
    Next
    Session.LCID = saveLCID
    %>
    </TABLE>
    ***********************

    Go on, try it.
    Old Pedant, Jul 29, 2008
    #5
  6. William (Tamarside)

    Old Pedant Guest

    "William (Tamarside)" wrote:

    > Well thank you so much for absolutely nothing! And here I thought
    > Google Groups was a community where one could ask others for help.


    First of all, this isn't "Google Groups." This is the Usenet. Google just
    gives you one of *many* ways to read (and write) UseNet messages. (For
    example, I happen to be using one provided by www.microsoft.com, right now.
    And if your ISP has the feeds, Outlook Express has a news reader/writer built
    in.)

    And, yes, you can ask others for help. But when you just toss code at us
    and say "it doesn't work" with no explanation of *what* doesn't work or what
    you have tried or what debug you have done... Well, sorry, but you are just
    asking for the kind of advice that both Evertjan and I gave you. Which is,
    quite honestly and without trying to be mean or nasty, that you should dump
    that junky old code and find better code.

    > A couple of points, though:
    > 2) The entire calendar works and works well, regardless of what you or
    > I may think of the coding standards.


    No, it doesn't "work well".
    (a) It obviously doesn't work well or you wouldn't have posted the question.
    (b) Even if it sort of works, it doesn't "work well" because it is using the
    horrible horrible practice of making one "hit" to the DB for every date in
    the calendar! Okay, maybe that doesn't matter in your inTRAnet system,
    where server performance is likely not an issue. But it's really really
    stretching it to say it "works WELL". "Works"? Okay. "Well"? Sorry, but
    no way.

    > 3) The problem I have is with the SQL query, as I don't get all the
    > dates where I know there are bookings.


    So why didn't you say that in the first post?

    And what debugging have you done to see just what you *are* getting from the
    SQL query?

    And what does the data inside the DB table look like?

    > 4) Next time you intend to be a smart-arse, try writing code in VB.Net
    > to allow for integration between Active Directory, Exchange, MOSS07
    > and two 3rd party apps.


    Well, if you can really do all that, then why are you using this ancient
    junky ASP calendar?? ASP.NET has a calendar control included. And there are
    tons of examples on the 'net on using that control. Mind you, I'm not all
    the enamored of the way even that control works, because it, too, makes a
    "filter" request on a DataTable for each date displayed. But at least it's
    not a complete DB hit each time.

    > 5) Being nice to people costs nothing, so when people ask for help,
    > either offer help or stay quiet.


    But don't forget that asking *organized* questions, rather than just "this
    doesn't work" and tossing code over the wall, costs nothing, too.

    Quite frankly, looking again at that code, I still don't see what the
    problem is. And I don't think I could find out unless I had your DB and the
    code in my hands. Or unless you started doing some debugging and said
    specifically "when the record in the DB contains x and y then it works, but
    not with z" (or something like that). But even so, then, there's no way I'd
    let that code stand, as is.
    Old Pedant, Jul 29, 2008
    #6
  7. William (Tamarside)

    Evertjan. Guest

    =?Utf-8?B?T2xkIFBlZGFudA==?= wrote on 29 jul 2008 in
    microsoft.public.inetserver.asp.general:

    > "Evertjan." wrote:
    >
    >> For the English, this function is build-in in VBS:
    >> MonthName(month[, abbreviate]),
    >> so even the function assignment will error,
    >> as the name is reserved.
    >>
    >> For other languages or more flexibility
    >> your code is simply silly in it's size,

    >
    > Ummm...For *all* languages, the MonthName function is builtin. You just
    > have to set the correct locale via Session.LCID.


    No, it is not. not in a "flexible" way. And "all" languages certeinly not.

    I could want to have a 4 letter abbreviation, in stead of the 3 letter
    offered, or want to have an abbr. "mrt" in stead of "maa", both are common
    in Dutch. Or I do want two languages in my serverside dating, or not bother
    with LCID, or do not know how another target server works or in my case
    just do not think MS can be trusted with formatting such things.

    Programmming your own formatting is also more fun.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jul 29, 2008
    #7
  8. William (Tamarside)

    Old Pedant Guest

    "Evertjan." wrote:

    > > Old Pedant wrote:
    > > Ummm...For *all* languages, the MonthName function is builtin. You just
    > > have to set the correct locale via Session.LCID.

    >
    > No, it is not. not in a "flexible" way. And "all" languages certeinly not.
    >
    > I could want to have a 4 letter abbreviation, in stead of the 3 letter
    > offered, or want to have an abbr. "mrt" in stead of "maa", both are common
    > in Dutch.


    Well, if it comes down to *THAT*, there are times in English where we don't
    use the same monthname abbreviations the MS supplies. For example, it's not
    uncommon to use 2-letter abbreviations when you need very compact text.
    Example:
    JA FB MR AP MY JN JL AU SE OC NO DE
    but other people might choose other 2-letter combinations.

    So, yeah, if you don't like the "standard" MS versions, you can easily "roll
    your own". But I think most people in most languages would be happy using
    the MS-supplied values. Even if not ideal, they should be adequate.

    > Programmming your own formatting is also more fun.


    LOL! Okay, now *that* is a valid reason! <grin/>
    Old Pedant, Jul 30, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RCS
    Replies:
    11
    Views:
    1,995
    connectingvivek
    Sep 20, 2009
  2. Leveridge Systems INC
    Replies:
    2
    Views:
    370
    David Harmon
    Jan 28, 2004
  3. Leveridge Systems INC
    Replies:
    2
    Views:
    275
    Jorge Rivera
    Jan 28, 2004
  4. javahead
    Replies:
    1
    Views:
    1,052
    Erik Max Francis
    Oct 8, 2003
  5. RCS
    Replies:
    4
    Views:
    134
Loading...

Share This Page