Newbie - Huge Select Case statement

T

Targa

My plan is to use select case to position style elements in a table but
since I have to allow for every minute of the day, the select case statement
will be quite huge. See code below.
Is there a better/more efficient way to do this?

Thanks!

<%
MySchedule=rs("MyStartTime")
SELECT CASE MySchedule

Case "12:00 AM"
Response.write "style=top: 19px;"

Case "12:01 AM"
Response.write "style=top: 20px;"

Case "12:02 AM"
Response.write "style=top: 21px;"

Case "12:03 AM"
Response.write "style=top: 22px;"

Case "12:04 AM"
Response.write "style=top: 23px;"

Case "12:05 AM"
Response.write "style=top: 24px;"

Case "12:06 AM"
Response.write "style=top: 25px;"

'***AND SO ON****

Case "11:59 PM"
Response.write "style=top: 1458px;"

END SELECT
%>
 
B

Bob Barrows

Targa said:
My plan is to use select case to position style elements in a table
but since I have to allow for every minute of the day, the select
case statement will be quite huge. See code below.
Is there a better/more efficient way to do this?

Thanks!

<%
MySchedule=rs("MyStartTime")
SELECT CASE MySchedule

Case "12:00 AM"
Response.write "style=top: 19px;"

Case "12:01 AM"
Response.write "style=top: 20px;"
<snip>

I don't know about you, but I see a pattern: the pixels go up one for every
minute. That seems to suggest a formula... Doesn't it?

How about:
Dim iTop, dSched
dSched = CDate(rs("MyStartTime"))
iTop = 19 + DateDiff("n",#12:00 AM#, dSched)
Response.write "style=""top: " & iTop & "px"""

HTH,
Bob Barrows
 
L

Lance Wynn

Hi,
Perhaps you could calculate the minute difference between the current time,
and 12:00 midnight, and then add 19 to it?


<%
MySchedule=rs("MyStartTime")
topOffset = Datediff("n","12:00 am", MySchedule) + 19
Response.write "style=top: " & topOffset & "px;"
%>

(I haven't tested this, but it should work.)

Lance
 
J

jenny mabe

Case "11:59 PM"
Response.write "style=top: 1458px;"

Just wondering, but isnt this going to position the element well off the
screen of most users?


Jenny
 
T

Targa

Perfect - Thanks!


Bob Barrows said:
<snip>

I don't know about you, but I see a pattern: the pixels go up one for every
minute. That seems to suggest a formula... Doesn't it?

How about:
Dim iTop, dSched
dSched = CDate(rs("MyStartTime"))
iTop = 19 + DateDiff("n",#12:00 AM#, dSched)
Response.write "style=""top: " & iTop & "px"""

HTH,
Bob Barrows
--
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"
 
T

Targa

Exactly what I was looking for!

Thanks!

Lance Wynn said:
Hi,
Perhaps you could calculate the minute difference between the current time,
and 12:00 midnight, and then add 19 to it?


<%
MySchedule=rs("MyStartTime")
topOffset = Datediff("n","12:00 am", MySchedule) + 19
Response.write "style=top: " & topOffset & "px;"
%>

(I haven't tested this, but it should work.)

Lance
 
T

Targa

Nope - All within a fixed height table inside <div></div> with overflow:
scroll


Case "11:59 PM"
Response.write "style=top: 1458px;"

Just wondering, but isnt this going to position the element well off the
screen of most users?


Jenny
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top