473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Serious help needed - Calendar!

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
%>
Jul 28 '08 #1
7 2271


"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.

Jul 29 '08 #2
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)
Jul 29 '08 #3
On 29 Jul, 08:01, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
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.
Jul 29 '08 #4
"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.

Jul 29 '08 #5
"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.
Jul 29 '08 #6
=?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)
Jul 29 '08 #7
"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/>
Jul 29 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Wm | last post by:
I have a client who needs a good web-based calendar for their website. What they would like is something that can display a monthly calendar online, with a display that's large enough that you can...
1
by: DavidM | last post by:
I'm currently developing a website for my company. I would like to provide list server functionality to the site, if possible. We have a third party mail service, so I can easily POP and SMTP. ...
2
by: Tony Ciconte | last post by:
There are many techniques and code snippets that will open a popup calendar so that you can pick and insert a date into Access. However, I have been unable to find a method to insert information...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
13
by: Alan M Dunsmuir | last post by:
I need to specify a new data type, almost entirely a 'clone' of the existing DateTime type, with the following specific difference, and all the consequent differences in properties and methods...
5
by: bromio | last post by:
can someone help me to make code for digital clock using AT89S52. The specs of clock are 12 hour clock,am-pm display,use timer interrupts to have delay.two external inputs to adjust hours and...
1
by: 848lu | last post by:
hey i really need help...i got this code....basically im suppose to make a calender that allows a user to type in month and year .... and the calander displays it on the scree using...
2
by: BerkshireGuy | last post by:
I need to create a form that is a giant calendar. For each day of the month (users should be able to browse the months) the date is a different color if: 1) The daily routine ran 2) If the...
56
by: Squishy | last post by:
I tried installing my VS2005 Pro on Vista Ultimate 32 bit RTM today and got errors stating that VS2005 was not compatible with Vista. Microsoft......please pull your finger out of my ass and tell...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.