473,387 Members | 1,431 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,387 software developers and data experts.

Easy solution?

I'm hoping for an easy solution to this that I'm not seeing that
someone more experienced will.

All I want to do it mark an option tag as selected....

<%
hourCounter = 1
Do WHILE hourCounter <= 12 %>
<option value="<%=hourCounter%>" <%If hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) Then Response.write "
selected" End If %>><%=hourCounter%></option>
<% hourCounter = hourCounter + 1
Loop
%>

The trouble is if the time is "PM" I have a problem as you can see. Is
there a method or property here I can implement that I'm not seeing?

Thanks!

Feb 8 '06 #1
10 1339
Where's PM coming in? Is your data stored as actual date/time data? Try
simplifying the code a little bit, at least as far as readability and fewer
reads of object data.
<%

Dim iSelectedHour
iSelectedHour = CInt(Hour(rsCalender.Fields.Item("fld_calendar_Dat eTime")))

hourCounter = 1
Do while hourCounter <= 12

%>
<option value="<%=hourCounter%>"<% If hourCounter = iSelectedHour Then
Response.Write " selected"%>><%=hourCounter%></option>
<%
hourCounter = hourCounter + 1
Loop
%>
Although, this doesn't really change much. Can you explain what PM problem
you're having?
Ray at home


"the other john" <ki*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm hoping for an easy solution to this that I'm not seeing that
someone more experienced will.

All I want to do it mark an option tag as selected....

<%
hourCounter = 1
Do WHILE hourCounter <= 12 %>
<option value="<%=hourCounter%>" <%If hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) Then Response.write "
selected" End If %>><%=hourCounter%></option>
<% hourCounter = hourCounter + 1
Loop
%>

The trouble is if the time is "PM" I have a problem as you can see. Is
there a method or property here I can implement that I'm not seeing?

Thanks!

Feb 8 '06 #2
"the other john" <ki*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm hoping for an easy solution to this that I'm not seeing that
someone more experienced will.

All I want to do it mark an option tag as selected....

<%
hourCounter = 1
Do WHILE hourCounter <= 12 %>
<option value="<%=hourCounter%>" <%If hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) Then Response.write "
selected" End If %>><%=hourCounter%></option>
<% hourCounter = hourCounter + 1
Loop
%>

The trouble is if the time is "PM" I have a problem as you can see. Is
there a method or property here I can implement that I'm not seeing?

Thanks!

How is "PM" a problem?

Hour() =
"Returns a whole number between 0 and 23,
inclusive, representing the hour of the day."

Thus, modifying your code, this should work;
(presuming your field is DateTime field):

<form>
<select>
<%
Dim hourCounter
hourCounter = 0
Dim hourRecord
hourRecord = Hour(rsCalendarEdit("fld_calendar_DateTime"))
Do While hourCounter < 24
%>
<option value="<%=hourCounter%>"
<%
If hourCounter = hourRecord Then
Response.Write " selected"
End If
%>

<%=hourCounter%>
</option>
<% hourCounter = hourCounter + 1
Loop
%>
</select>
</form>

Or do you not want to use military time?
Feb 8 '06 #3
The trouble I'm having with PM is that the client chooses their time
via a dropbox. The script it intended for an edit page where the time
already exists in the database. The trouble with PM is when the time
is PM this script is looking for "6" but the time in the database is
"18".

Feb 8 '06 #4
"the other john" <ki*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
The trouble I'm having with PM is that the client chooses their time
via a dropbox. The script it intended for an edit page where the time
already exists in the database. The trouble with PM is when the time
is PM this script is looking for "6" but the time in the database is
"18".

Try this:

<form>
<select>
<%
Dim hourArray(23)
hourArray(0) = "12:00 AM"
hourArray(1) = "1:00 AM"
hourArray(2) = "2:00 AM"
hourArray(3) = "3:00 AM"
hourArray(4) = "4:00 AM"
hourArray(5) = "5:00 AM"
hourArray(6) = "6:00 AM"
hourArray(7) = "7:00 AM"
hourArray(8) = "8:00 AM"
hourArray(9) = "9:00 AM"
hourArray(10) = "10:00 AM"
hourArray(11) = "11:00 AM"
hourArray(12) = "12:00 PM"
hourArray(13) = "1:00 PM"
hourArray(14) = "2:00 PM"
hourArray(15) = "3:00 PM"
hourArray(16) = "4:00 PM"
hourArray(17) = "5:00 PM"
hourArray(18) = "6:00 PM"
hourArray(19) = "7:00 PM"
hourArray(20) = "8:00 PM"
hourArray(21) = "9:00 PM"
hourArray(22) = "10:00 PM"
hourArray(23) = "11:00 PM"
Dim hourCounter
hourCounter = 0
For hourCounter = 0 To UBound(hourArray)
%>
<option value="<%=hourCounter%>"
<% If hourCounter = rsCalendarEdit("fld_calendar_DateTime") Then
Response.Write " selected"
End If
%>

<%=hourArray(hourCounter)%>
</option>
<%
Next
%>
</select>
</form>
Feb 8 '06 #5
this is an example I laid out the other day... might be useful...

heres the output :

You are going to experience problems with this method unless you format your
Date from SQL in an acceptable format ( as presented below ) before it hits
your JS code.

01-24-2006 13:30:00

Tue Jan 24 13:30:00 PST 2006
1:30 PM
The time is now : 8:32 AM

D.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<pre>
You are going to experience problems with this method unless you format your
Date from SQL in an acceptable format ( as presented below ) before it hits
your JS code.

01-24-2006 13:30:00
</pre>

<script>

Date.prototype.humanTime = function () {
var sDate = new String(), sHour = new String(), sAMPM = new String();
sHour = this.getHours() % 12 ;
sAMPM = parseInt(this.getHours()) > 11 ? ' PM' : ' AM';
if (sHour == 0) sHour = 12;
sDate = sHour + ':' + this.getMinutes() + sAMPM;
return (sDate.toString());
}
var someDate= new Date('01-24-2006 13:30:00');
document.write ( '<pre>' + someDate.toString() + '<br />')
document.write ( someDate.humanTime() + '<br />')

var sNow = new Date()
document.write ( 'The time is now : ' + sNow.humanTime() )

document.write ( '</pre>' )

</script>
</body>
</html>

the other john wrote:
The trouble I'm having with PM is that the client chooses their time
via a dropbox. The script it intended for an edit page where the time
already exists in the database. The trouble with PM is when the time
is PM this script is looking for "6" but the time in the database is
"18".

Feb 8 '06 #6
What I actually need just the hour number. I was hoping the following
would work but it doesn't, any idea why?
<%
hourCounter = 1
Do WHILE hourCounter <= 12 %>
<option value="<%=hourCounter%>" <%If hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) OR hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) + 12 Then Response.write
" selected" End If %>><%=hourCounter%></option>
<% hourCounter = hourCounter + 1
Loop
%>
Thanks again all!

Feb 9 '06 #7
"the other john" <ki*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
What I actually need just the hour number. I was hoping the following
would work but it doesn't, any idea why?
<%
hourCounter = 1
Do WHILE hourCounter <= 12 %>
<option value="<%=hourCounter%>" <%If hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) OR hourCounter =
hour(rsCalendarEdit("fld_calendar_DateTime")) + 12 Then Response.write
" selected" End If %>><%=hourCounter%></option>
<% hourCounter = hourCounter + 1
Loop
%>
Thanks again all!


Try " - 12" instead of " + 12" as Hour() returns 0 to 23.
Feb 9 '06 #8
ah HA, success! But I don't understand why. - rather than + ...I'm
cOnFuSeD

Feb 10 '06 #9
"the other john" <ki*****@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
ah HA, success! But I don't understand why. - rather than + ...I'm
cOnFuSeD


I like to separate logic from display so here's a rewrite of your code:

<%
Option Explicit
Dim hourOp
hourOp = ""
Dim hourIf
hourIf = Hour(rsCalendarEdit("fld_calendar_DateTime"))
If hourIf = 0 Then hourIf = 24
If hourIf > 12 Then hourIf = hourIf - 12
Dim hourIs
For hourIs = 1 To 12
hourOp = hourOp & "<option value='" & hourIs & "'"
If hourIs = hourIf Then hourOp = hourOp & " selected"
hourOp = hourOp & "></option>" & vbCrLf
Next
%>

<%=hourOp%>

From the above:
a) "hourIs" (your "hourCounter") goes from 0 to 12.
b) "hourIf" (from your recordset) may be 0 to 23.
c) "hourOp" is all of the "<option>" tags.

Thus, to compare "hourIs" to "hourIf", you'll have
to subtract 12 from "hourIf" when it's greater than 12.

But, what was handled before, was when "hourIf" was 0.
Now, since 0 is Midnight, I change it to 24.

Does that help you understand?
Feb 10 '06 #10
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:B9******************************@comcast.com. ..

[snip]

Oops.
For hourIs = 1 To 12 a) "hourIs" (your "hourCounter") goes from 0 to 12.


should be

a) "hourIs" (your "hourCounter") goes from 1 to 12.
Feb 10 '06 #11

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

Similar topics

0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
2
by: andy.dreistadt | last post by:
Hi all, I came across another problem that is probably pretty easy but, again, due to my rusty-ness with C, I'm a little stumped. I have a struct that looks like this: /* Instrument Data...
8
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the...
23
by: **Developer** | last post by:
Is there an easy way to copies all files in a directory into another directory? What about coping subdirectories too? Thanks in advance for any info
7
by: Shadow Lynx | last post by:
I realize that his question has been asked, in many other forms, many times in this group. Even so, my tired eyes have not yet found a sufficient answer, so I've decided to "reask" it even though...
8
by: mindwarp | last post by:
Hi, When a user submits / posts data my php script Inserts data into my database. If they refresh the script or click back and click submit again I get duplicate record. Is there an easy...
7
by: SteveM | last post by:
I am sure this is an easy question, but being relatively new to ASP.NET programming, I can not quite grasp what I need to accomplish what I need to do. What I have is a word document that is...
3
by: miya | last post by:
On Apr 26, 4:36 pm, bvidinli <bvidi...@gmail.comwrote: Django is the way to go for web development. http://www.djangoproject.com/ cya -- Nicolás Miyasato ( miya )
10
by: erokar | last post by:
Which tools would you use? I want the interface design to be as easy and fast as possible, all ideology aside. I'm considering either IronPython+Visual Studio or Python+Qt -- but I'm open for other...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.