Loop

B

Brian

Hi,

Total newb here so my apologies if I break any scripting standards. I
have some code that pulls reservation times from a database. It is
supposed to print green cells in a table until the time of the
reservation and then print red cells until the reserved period has
ended and then continue printing green cells. Example: reservation
period is 11:00 AM to 2:00 PM. Print green cells until representing
every half hour until 11. Print red cells until 2 then print green
cells until end of day(7 PM). I ran into a problem and statically
assigned values to take the DB out of the loop. Below is the code. Can
anyone tell me why is it that if the reservation start time is before
9:30 AM that the loop breaks and doesn't print red cells. Sorry for
being lengthy,...

Brian


<%

vtime = TimeValue(#7:00#)
btime = TimeValue(#9:30#)


Response.Write "<table border=1>"

For i = 1 to 30

If vtime > btime AND vtime < TimeValue(#12:31#) Then
Response.Write "<td bgcolor='#F0E68C'>" & Left(vtime, 5) & "</td>"
vtime = DateAdd("n", 30, vtime)

Else

Response.Write "<td bgcolor='#F0E68C'>" & Left(vtime, 4) & "</td>"
vtime = DateAdd("n", 30, vtime)

End If
Next
Response.Write "</tr>"


vtime = TimeValue(#7:00#)
stime = TimeValue(#8:00#)
btime = TimeValue(#9:30#)
etime = TimeValue(#11:00#)

Response.Write "<tr height=20>"



Do while Left(vtime, 4) <> Left(stime, 4)

Response.Write "<td bgcolor='#3CB371'></td>"

vtime = DateAdd("n", 30, vtime)



Loop



Do while Left(vtime, 4) <= Left(etime, 5)

Response.Write "<td bgcolor='#F08080'></td>"

vtime = DateAdd("n", 30, vtime)

Loop









Response.Write "</table>"

%>
 
C

Chris Hohmann

Brian said:
Hi,

Total newb here so my apologies if I break any scripting standards. I
have some code that pulls reservation times from a database. It is
supposed to print green cells in a table until the time of the
reservation and then print red cells until the reserved period has
ended and then continue printing green cells. Example: reservation
period is 11:00 AM to 2:00 PM. Print green cells until representing
every half hour until 11. Print red cells until 2 then print green
cells until end of day(7 PM). I ran into a problem and statically
assigned values to take the DB out of the loop. Below is the code. Can
anyone tell me why is it that if the reservation start time is before
9:30 AM that the loop breaks and doesn't print red cells. Sorry for
being lengthy,...

Brian


<%

vtime = TimeValue(#7:00#)
btime = TimeValue(#9:30#)


Response.Write "<table border=1>"

For i = 1 to 30

If vtime > btime AND vtime < TimeValue(#12:31#) Then
Response.Write "<td bgcolor='#F0E68C'>" & Left(vtime, 5) & "</td>"
vtime = DateAdd("n", 30, vtime)

Else

Response.Write "<td bgcolor='#F0E68C'>" & Left(vtime, 4) & "</td>"
vtime = DateAdd("n", 30, vtime)

End If
Next
Response.Write "</tr>"


vtime = TimeValue(#7:00#)
stime = TimeValue(#8:00#)
btime = TimeValue(#9:30#)
etime = TimeValue(#11:00#)

Response.Write "<tr height=20>"



Do while Left(vtime, 4) <> Left(stime, 4)

Response.Write "<td bgcolor='#3CB371'></td>"

vtime = DateAdd("n", 30, vtime)



Loop



Do while Left(vtime, 4) <= Left(etime, 5)

Response.Write "<td bgcolor='#F08080'></td>"

vtime = DateAdd("n", 30, vtime)

Loop









Response.Write "</table>"

%>

By using the Left function, your comparing string values not time
values. As such, lexically (alphabetically), "8:00" occurs after
"11:00". Here's some revised code for your review:

<%
Dim d,s,e,i
s = #11:00:00#
e = #14:00:00#

With Response
.Write "<table border='1'>"
.Write "<tr>"
For i = 14 To 35
d = DateAdd("n",i*30,0)
.Write "<td bgcolor='F0E68C'>"
.Write FormatDateTime(d,vbShortTime)
.Write "</td>"
Next
.Write "</tr>"

.Write "<tr>"
For i = 14 To 35
d = DateAdd("n",i*30,0)
If (e > d) And (s < DateAdd("n",30,d)) Then
.Write "<td bgcolor='#F08080'>&nbsp;</td>"
Else
.Write "<td bgcolor='#3CB371'>&nbsp;</td>"
End If
Next
.Write "</tr>"
.Write "</table>"
End With
%>

Notes:
1. Consider using ISO-8601 standard date/time formats (yyyy-mm-dd
hh:nn:ss)
2. Consider using a browser-safe color palette.
3. Refer to the following article for advice on formatting date/time
values. aspfaq.com/2313

HTH
-Chris Hohmann
 
B

Brian

Chris Hohmann said:
By using the Left function, your comparing string values not time
values. As such, lexically (alphabetically), "8:00" occurs after
"11:00". Here's some revised code for your review:

<%
Dim d,s,e,i
s = #11:00:00#
e = #14:00:00#

With Response
.Write "<table border='1'>"
.Write "<tr>"
For i = 14 To 35
d = DateAdd("n",i*30,0)
.Write "<td bgcolor='F0E68C'>"
.Write FormatDateTime(d,vbShortTime)
.Write "</td>"
Next
.Write "</tr>"

.Write "<tr>"
For i = 14 To 35
d = DateAdd("n",i*30,0)
If (e > d) And (s < DateAdd("n",30,d)) Then
.Write "<td bgcolor='#F08080'>&nbsp;</td>"
Else
.Write "<td bgcolor='#3CB371'>&nbsp;</td>"
End If
Next
.Write "</tr>"
.Write "</table>"
End With
%>

Notes:
1. Consider using ISO-8601 standard date/time formats (yyyy-mm-dd
hh:nn:ss)
2. Consider using a browser-safe color palette.
3. Refer to the following article for advice on formatting date/time
values. aspfaq.com/2313

HTH
-Chris Hohmann

Yes, that helps a lot. It makes sense now. Thank you.
Just curious, why do you say that I should consider using a
browser-safe color palette?

Brian
 
C

Chris Hohmann

Brian said:
Yes, that helps a lot. It makes sense now. Thank you.
Just curious, why do you say that I should consider using a
browser-safe color palette?

Force of habit mainly. :) It's really not that much of an issue anymore.
Here are some points:

1. Some miniscule fraction of your user population may be using 8 bit
(256) color depth. For those people, a browser safe palette avoids
dithering.

2. There no harm in using a browser-safe palette. True/high color
displays deal with them as well as they do any other color.

3. Browser-safe palettes may come into vogue again as more web content
is "retooled" for mobile display technologies (PDA's, mobile phones,
etc...) with limited color depths

4. CSS allows you to abbreviate browser safe hex codes. For example, you
can specify #f00 for red.

Here are some articles:
http://www.lynda.com/hex.html
http://hotwired.lycos.com/webmonkey/00/37/index2a.html?tw=design

HTH
-Chris
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top