
Response.Write Date() problems
I'm trying to display a weekly calendar with the month and year on top and
the current date in an alternate color, but nothing prints out on my test
page when viewed in IE7.
Is there something fundamentally wrong with my code, is it my browser, or
does this not show up when displayed on my PC?
Here is all of the code (nice and small):
<% [at] Language="VBSCRIPT"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<%
Dim i As Integer
Response.Write("<table><tr><td class=""mmyy"">start1" & Month(Date()) & "
" & Year(Date()) & "end1</td></tr><tr>")
For i = 1 To 7
Response.Write("<td class=""" & ((i=WeekDay(Date())?"day":"reg") & """>"
& Day(Date()) & "</td>")
Next i
Response.Write("</tr></table>")
%>
<html>
<head>
<title>Weekly Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
td { background-color:Black; height:24px; width:24px; font-size:
12pt; color:Red; }
td.mmyy { background-color:Silver; height:24px; width:24px; }
td.day { background-color:Yellow; height:24px; width:24px; }
td.reg { color:White; }
</style>
</head>
<body>
<table>
<tr><td class="mmyy" colspan="7">start2<% Response.Write(Month(Date()) &
" " & Year(Date())) %>end2</td></tr>
<tr>
<%
Dim i As Integer
For i = 1 To 7
Response.Write("<td class=""")
If (i = WeekDay(Date())) Then
Response.Write("day")
Else
Response.Write("reg")
End If
Response.Write(""">" & Day(Date()) & "</td>")
Next
%>
</tr>
</table>
<hr />
<table>
<tr><td class="mmyy" colspan="7">start3<% Response.Write(Month(Date()) &
" " & Year(Date())) %>end3</td></tr>
<tr>
<%
Dim i As Integer
For i = 1 To 7
Response.Write("<td class=""" & ((i=WeekDay(Date())?"day":"reg") &
""">" & Day(Date()) & "</td>")
Next
%>
</tr>
</table>
</body>
</html>
Re: Response.Write Date() problems
these lines are bogus:
--> Dim i As Integer
use :
Dim i 'As Integer
not sure what you're trying to get, but this line is erroneous:
-->Response.Write("<td class=""" & ((i=WeekDay(Date())?"day":"reg") & """>"
can't put a formula in a write statement
Re: Response.Write Date() problems
jp2code wrote:
> I'm trying to display a weekly calendar with the month and year on
> top and the current date in an alternate color, but nothing prints
> out on my test page when viewed in IE7.
>
> Is there something fundamentally wrong with my code, is it my
> browser, or does this not show up when displayed on my PC?
>
> Here is all of the code (nice and small):
>
If I was going to debug this, I would start by commenting out everything
until I got some output in the browser, then adding stuff back in until it
broke again.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Re: Response.Write Date() problems
This *is* my cut down version.
There are just 3 ways of showing the same thing - each way failed.
All this example is trying to do is populate a table using Response.Write.
I'll look into Jon Paal's answer; it may have solved the problem.
"Bob Barrows [MVP]" <reb01501 [at] NOyahoo.SPAMcom> wrote in message
news:Opvr6s8%23HHA.1164 [at] TK2MSFTNGP02.phx.gbl...
> jp2code wrote:
>> I'm trying to display a weekly calendar with the month and year on
>> top and the current date in an alternate color, but nothing prints
>> out on my test page when viewed in IE7.
>>
>> Is there something fundamentally wrong with my code, is it my
>> browser, or does this not show up when displayed on my PC?
>>
>> Here is all of the code (nice and small):
>>
>
> If I was going to debug this, I would start by commenting out everything
> until I got some output in the browser, then adding stuff back in until it
> broke again.
>
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
Re: Response.Write Date() problems
Mr. Paal,
I removed the "As Integer" section, still no output, so I edited the code to
this version (below) which still does not work. All it outputs are two
tables (not 3): "start2end2" and "start3end3" - but at least with the
"start3end3" table, I can also see the second row.
Can you get this to display in a web page? Here is the code:
<% [at] Language="VBSCRIPT"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<%
Dim sun, mon, tue, wed, thr, fri, sat, monthYear
sun = (1 = WeekDay(Date())) ? "day" : "reg"
mon = (2 = WeekDay(Date())) ? "day" : "reg"
tue = (3 = WeekDay(Date())) ? "day" : "reg"
wed = (4 = WeekDay(Date())) ? "day" : "reg"
thr = (5 = WeekDay(Date())) ? "day" : "reg"
fri = (6 = WeekDay(Date())) ? "day" : "reg"
sat = (7 = WeekDay(Date())) ? "day" : "reg"
monthYear = Month(Date()) & " " & Year(Date())
%>
<html>
<head>
<title>Weekly Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
td { background-color:Black; height:24px; width:24px; font-size:
12pt; color:Red; }
td.mmyy { background-color:Silver; height:24px; width:24px; }
td.day { background-color:Yellow; height:24px; width:24px; }
td.reg { color:White; }
</style>
</head>
<body>
<table>
<tr><td class="mmyy" colspan="7">start2<% Response.Write(monthYear)
%>end2</td></tr>
<tr>
<%
Dim i
For i = 1 To 7
Response.Write("<td class=""")
If (i = WeekDay(Date())) Then
Response.Write("day")
Else
Response.Write("reg")
End If
Response.Write(""">" & Day(Date()) & "</td>")
Next
%>
</tr>
</table>
<hr />
<table>
<tr><td class="mmyy" colspan="7">start3<% Response.Write(monthYear)
%>end3</td></tr>
<tr>
<td class=<%=sun%>><% Response.Write(WeekDay(Date())) %></td>
<td class=<%=mon%>><% Response.Write(mon) %></td>
<td class=<%=tue%>><% Response.Write("18") %></td>
<td class=<%=wed%>><%=wed%></td>
<td class=<%=thr%>><% Response.Write(WeekDay("September 20, 2007"))
%></td>
<td><%=fri%></td>
<td class=<%=sat%>><% Response.Write(WeekDay("September 22, 2007"))
%></td>
</tr>
</table>
</body>
</html>
"Jon Paal [MSMD]" <Jon nospam Paal [at] everywhere dot com> wrote in message
news:13f5ontdc8p6gbe [at] corp.supernews.com...
>
> these lines are bogus:
>
> --> Dim i As Integer
>
> use :
>
> Dim i 'As Integer
>
> not sure what you're trying to get, but this line is erroneous:
>
> -->Response.Write("<td class=""" & ((i=WeekDay(Date())?"day":"reg") &
> """>"
>
> can't put a formula in a write statement
>
>
>
>
Re: Response.Write Date() problems
these lines are bogus:
sun = (1 = WeekDay(Date())) ? "day" : "reg"
....
not sure what you're trying to get here..
The weekday number can be obtained as "WeekDay(Date())"
example:
Dim MyDate, MyWeekDay
MyDate = #October 19, 1962# ' Assign a date.
MyWeekDay = Weekday(MyDate) ' MyWeekDay contains 6 because MyDate represents a Friday.
"jp2code" <poojo.com/mail> wrote in message news:OYD5l%238%23HHA.980 [at] TK2MSFTNGP06.phx.gbl...
> Mr. Paal,
>
> I removed the "As Integer" section, still no output, so I edited the code to this version (below) which still does not work. All
> it outputs are two tables (not 3): "start2end2" and "start3end3" - but at least with the "start3end3" table, I can also see the
> second row.
>
> Can you get this to display in a web page? Here is the code:
>
> <% [at] Language="VBSCRIPT"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
> <%
> Dim sun, mon, tue, wed, thr, fri, sat, monthYear
> sun = (1 = WeekDay(Date())) ? "day" : "reg"
> mon = (2 = WeekDay(Date())) ? "day" : "reg"
> tue = (3 = WeekDay(Date())) ? "day" : "reg"
> wed = (4 = WeekDay(Date())) ? "day" : "reg"
> thr = (5 = WeekDay(Date())) ? "day" : "reg"
> fri = (6 = WeekDay(Date())) ? "day" : "reg"
> sat = (7 = WeekDay(Date())) ? "day" : "reg"
> monthYear = Month(Date()) & " " & Year(Date())
> %>
> <html>
> <head>
> <title>Weekly Calendar</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> <style type="text/css">
> td { background-color:Black; height:24px; width:24px; font-size: 12pt; color:Red; }
> td.mmyy { background-color:Silver; height:24px; width:24px; }
> td.day { background-color:Yellow; height:24px; width:24px; }
> td.reg { color:White; }
> </style>
> </head>
> <body>
> <table>
> <tr><td class="mmyy" colspan="7">start2<% Response.Write(monthYear) %>end2</td></tr>
> <tr>
> <%
> Dim i
> For i = 1 To 7
> Response.Write("<td class=""")
> If (i = WeekDay(Date())) Then
> Response.Write("day")
> Else
> Response.Write("reg")
> End If
> Response.Write(""">" & Day(Date()) & "</td>")
> Next
> %>
> </tr>
> </table>
> <hr />
> <table>
> <tr><td class="mmyy" colspan="7">start3<% Response.Write(monthYear) %>end3</td></tr>
> <tr>
> <td class=<%=sun%>><% Response.Write(WeekDay(Date())) %></td>
> <td class=<%=mon%>><% Response.Write(mon) %></td>
> <td class=<%=tue%>><% Response.Write("18") %></td>
> <td class=<%=wed%>><%=wed%></td>
> <td class=<%=thr%>><% Response.Write(WeekDay("September 20, 2007")) %></td>
> <td><%=fri%></td>
> <td class=<%=sat%>><% Response.Write(WeekDay("September 22, 2007")) %></td>
> </tr>
> </table>
> </body>
> </html>
>
> "Jon Paal [MSMD]" <Jon nospam Paal [at] everywhere dot com> wrote in message news:13f5ontdc8p6gbe [at] corp.supernews.com...
>>
>> these lines are bogus:
>>
>> --> Dim i As Integer
>>
>> use :
>>
>> Dim i 'As Integer
>>
>> not sure what you're trying to get, but this line is erroneous:
>>
>> -->Response.Write("<td class=""" & ((i=WeekDay(Date())?"day":"reg") & """>"
>>
>> can't put a formula in a write statement
>>
>>
>>
>>
>
>
Re: Response.Write Date() problems
>> sun = (1 = WeekDay(Date())) ? "day" : "reg"
There is not a ternary operator in VbScript.
Bob Lehmann
"jp2code" <poojo.com/mail> wrote in message
news:OYD5l%238%23HHA.980 [at] TK2MSFTNGP06.phx.gbl...
> Mr. Paal,
>
> I removed the "As Integer" section, still no output, so I edited the code
to
> this version (below) which still does not work. All it outputs are two
> tables (not 3): "start2end2" and "start3end3" - but at least with the
> "start3end3" table, I can also see the second row.
>
> Can you get this to display in a web page? Here is the code:
>
> <% [at] Language="VBSCRIPT"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <%
> Dim sun, mon, tue, wed, thr, fri, sat, monthYear
> sun = (1 = WeekDay(Date())) ? "day" : "reg"
> mon = (2 = WeekDay(Date())) ? "day" : "reg"
> tue = (3 = WeekDay(Date())) ? "day" : "reg"
> wed = (4 = WeekDay(Date())) ? "day" : "reg"
> thr = (5 = WeekDay(Date())) ? "day" : "reg"
> fri = (6 = WeekDay(Date())) ? "day" : "reg"
> sat = (7 = WeekDay(Date())) ? "day" : "reg"
> monthYear = Month(Date()) & " " & Year(Date())
> %>
> <html>
> <head>
> <title>Weekly Calendar</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
> <style type="text/css">
> td { background-color:Black; height:24px; width:24px;
font-size:
> 12pt; color:Red; }
> td.mmyy { background-color:Silver; height:24px; width:24px; }
> td.day { background-color:Yellow; height:24px; width:24px; }
> td.reg { color:White; }
> </style>
> </head>
> <body>
> <table>
> <tr><td class="mmyy" colspan="7">start2<% Response.Write(monthYear)
> %>end2</td></tr>
> <tr>
> <%
> Dim i
> For i = 1 To 7
> Response.Write("<td class=""")
> If (i = WeekDay(Date())) Then
> Response.Write("day")
> Else
> Response.Write("reg")
> End If
> Response.Write(""">" & Day(Date()) & "</td>")
> Next
> %>
> </tr>
> </table>
> <hr />
> <table>
> <tr><td class="mmyy" colspan="7">start3<% Response.Write(monthYear)
> %>end3</td></tr>
> <tr>
> <td class=<%=sun%>><% Response.Write(WeekDay(Date())) %></td>
> <td class=<%=mon%>><% Response.Write(mon) %></td>
> <td class=<%=tue%>><% Response.Write("18") %></td>
> <td class=<%=wed%>><%=wed%></td>
> <td class=<%=thr%>><% Response.Write(WeekDay("September 20, 2007"))
> %></td>
> <td><%=fri%></td>
> <td class=<%=sat%>><% Response.Write(WeekDay("September 22, 2007"))
> %></td>
> </tr>
> </table>
> </body>
> </html>
>
> "Jon Paal [MSMD]" <Jon nospam Paal [at] everywhere dot com> wrote in message
> news:13f5ontdc8p6gbe [at] corp.supernews.com...
> >
> > these lines are bogus:
> >
> > --> Dim i As Integer
> >
> > use :
> >
> > Dim i 'As Integer
> >
> > not sure what you're trying to get, but this line is erroneous:
> >
> > -->Response.Write("<td class=""" & ((i=WeekDay(Date())?"day":"reg") &
> > """>"
> >
> > can't put a formula in a write statement
> >
> >
> >
> >
>
>
Re: Response.Write Date() problems
Jon Paal [MSMD] wrote on 21 sep 2007 in
microsoft.public.inetserver.asp.general:
> these lines are bogus:
>
> sun = (1 = WeekDay(Date())) ? "day" : "reg"
> ...
>
> not sure what you're trying to get here..
> The weekday number can be obtained as "WeekDay(Date())"
>
If the OP corrects that error,
using Date() again and again
could get the OP two different dates
in the same execution once in a while
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Response.Write Date() problems
"Evertjan." <exjxw.hannivoort [at] interxnl.net> wrote in message
news:Xns99B2637CD6EACeejj99 [at] 194.109.133.242...
> Jon Paal [MSMD] wrote on 21 sep 2007 in
> microsoft.public.inetserver.asp.general:
>
> > these lines are bogus:
> >
> > sun = (1 = WeekDay(Date())) ? "day" : "reg"
> > ...
> >
> > not sure what you're trying to get here..
> > The weekday number can be obtained as "WeekDay(Date())"
> >
>
> If the OP corrects that error,
> using Date() again and again
> could get the OP two different dates
> in the same execution once in a while
>
Don't you mean once in a blue moon.
--
Anthony Jones - MVP ASP/ASP.NET
Re: Response.Write Date() problems
"jp2code" <poojo.com/mail> wrote in message
news:OYD5l%238%23HHA.980 [at] TK2MSFTNGP06.phx.gbl...
> Mr. Paal,
>
> I removed the "As Integer" section, still no output, so I edited the code
to
> this version (below) which still does not work. All it outputs are two
> tables (not 3): "start2end2" and "start3end3" - but at least with the
> "start3end3" table, I can also see the second row.
>
> Can you get this to display in a web page? Here is the code:
>
> <% [at] Language="VBSCRIPT"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <%
> Dim sun, mon, tue, wed, thr, fri, sat, monthYear
> sun = (1 = WeekDay(Date())) ? "day" : "reg"
> mon = (2 = WeekDay(Date())) ? "day" : "reg"
> tue = (3 = WeekDay(Date())) ? "day" : "reg"
> wed = (4 = WeekDay(Date())) ? "day" : "reg"
> thr = (5 = WeekDay(Date())) ? "day" : "reg"
> fri = (6 = WeekDay(Date())) ? "day" : "reg"
> sat = (7 = WeekDay(Date())) ? "day" : "reg"
> monthYear = Month(Date()) & " " & Year(Date())
> %>
> <html>
> <head>
> <title>Weekly Calendar</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
> <style type="text/css">
> td { background-color:Black; height:24px; width:24px;
font-size:
> 12pt; color:Red; }
> td.mmyy { background-color:Silver; height:24px; width:24px; }
> td.day { background-color:Yellow; height:24px; width:24px; }
> td.reg { color:White; }
> </style>
> </head>
> <body>
> <table>
> <tr><td class="mmyy" colspan="7">start2<% Response.Write(monthYear)
> %>end2</td></tr>
> <tr>
> <%
> Dim i
> For i = 1 To 7
> Response.Write("<td class=""")
> If (i = WeekDay(Date())) Then
> Response.Write("day")
> Else
> Response.Write("reg")
> End If
> Response.Write(""">" & Day(Date()) & "</td>")
> Next
> %>
> </tr>
> </table>
> <hr />
> <table>
> <tr><td class="mmyy" colspan="7">start3<% Response.Write(monthYear)
> %>end3</td></tr>
> <tr>
> <td class=<%=sun%>><% Response.Write(WeekDay(Date())) %></td>
> <td class=<%=mon%>><% Response.Write(mon) %></td>
> <td class=<%=tue%>><% Response.Write("18") %></td>
> <td class=<%=wed%>><%=wed%></td>
> <td class=<%=thr%>><% Response.Write(WeekDay("September 20, 2007"))
> %></td>
> <td><%=fri%></td>
> <td class=<%=sat%>><% Response.Write(WeekDay("September 22, 2007"))
> %></td>
> </tr>
> </table>
> </body>
> </html>
>
Is this what you are trying to do:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<%
Dim i
Dim mdatToday : mdatToday = Date()
Function GetTDClass(rlWeekDay)
If rlWeekDay = WeekDay(mdatToday) Then
GetTDClass = "day"
Else
GetTDClass = "reg"
End If
End Function
Function GetMonthYear()
GetMonthYear = Month(mdatToday) & " " & Year(mdatToday)
End Function
Function DayFromWeekDay(rlWeekDay)
DayFromWeekDay = Day(mdatToday - (WeekDay(mdatToday) - rlWeekDay))
End Function
%>
<html>
<head>
<title>Weekly Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
td { font-size: 12pt; color:Red; height:24px;}
td.mmyy { background-color:Silver; }
td.day { background-color:Yellow; width:24px; }
td.reg { background-color:Black; color:White; width:24px; }
</style>
</head>
<body>
<table>
<tr><td class="mmyy" colspan="7"><%=GetMonthYear()%></td></tr>
<tr>
<%
For i = 1 To 7
Response.Write "<td class=""" & GetTDClass(i) & """>" & DayFromWeekDay(i) &
"</td>" & vbCrLf
Next
%>
</tr>
</table>
</body>
</html>
An often overlooked feature of VBScript (esp. by ASPers) is the Function.
--
Anthony Jones - MVP ASP/ASP.NET
Re: Response.Write Date() problems
That is exactly what I was trying to do!
I suppose my ASP pages need to start being coded in JScript; the syntax
differences between JavaScript and VBScript keep getting me into trouble.
Thanks!
"Anthony Jones" wrote:
> Is this what you are trying to do:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <%
> Dim i
> Dim mdatToday : mdatToday = Date()
>
> Function GetTDClass(rlWeekDay)
> If rlWeekDay = WeekDay(mdatToday) Then
> GetTDClass = "day"
> Else
> GetTDClass = "reg"
> End If
> End Function
>
> Function GetMonthYear()
> GetMonthYear = Month(mdatToday) & " " & Year(mdatToday)
> End Function
>
> Function DayFromWeekDay(rlWeekDay)
> DayFromWeekDay = Day(mdatToday - (WeekDay(mdatToday) - rlWeekDay))
> End Function
>
> %>
> <html>
> <head>
> <title>Weekly Calendar</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
> />
> <style type="text/css">
> td { font-size: 12pt; color:Red; height:24px;}
> td.mmyy { background-color:Silver; }
> td.day { background-color:Yellow; width:24px; }
> td.reg { background-color:Black; color:White; width:24px; }
> </style>
> </head>
> <body>
> <table>
> <tr><td class="mmyy" colspan="7"><%=GetMonthYear()%></td></tr>
> <tr>
> <%
> For i = 1 To 7
> Response.Write "<td class=""" & GetTDClass(i) & """>" & DayFromWeekDay(i)
> &
> "</td>" & vbCrLf
> Next
> %>
> </tr>
> </table>
> </body>
> </html>
>
> An often overlooked feature of VBScript (esp. by ASPers) is the Function.
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>