Response.Write Date() problems

J

jp2code

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):

<%@ 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>
 
B

Bob Barrows [MVP]

jp2code said:
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.
 
J

jp2code

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

jp2code

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:

<%@ 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>
 
B

Bob Lehmann

sun = (1 = WeekDay(Date())) ? "day" : "reg"
There is not a ternary operator in VbScript.

Bob Lehmann
 
E

Evertjan.

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
 
A

Anthony Jones

Evertjan. said:
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.
 
A

Anthony Jones

jp2code said:
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:

<%@ 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.
 
J

jp2code

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top