Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using If-Then Within a Loop 1

Status
Not open for further replies.

pupadu

Programmer
Mar 18, 2005
24
US
Hello everyone and anyone. I'm a novice at ASP but am learning a great deal from this forum. I have a piece of looping code that I'm trying to manipulate to look at an if-then, but I'm not sure that it's possible.

I'll do my best to explain this. The code creates a drop-box. It's contents of the drop-box is derived by the looping code. This code takes data from two fields in a MSSQL DB table (personnel). A specific amount of time is added to the value of one field and continues to add this amount of time until it reaches the value in the other field. Thus displaying all of the results in the drop box. When a user makes a choice and clicks submit, this choice is saved in another MSSQL DB table (schedule). When the user wants to edit the schedule table, the choice that the user originally chose is NOT selected in the drop-box.

Here is the originally code for the loop (this works fine):

<SELECT NAME="bhsunopen">
<%
Dim strSunapptframe
strSunapptframe = "30"
addTime = dateadd("H","0",strSunOpen)

Do While addTime <= dateadd("H","0",strSunClose)
addTime = DateAdd("n",strSunapptframe,addTime)
Response.Write "<OPTION VALUE=" & addTime & ">" & addTime & "</OPTION>"
Loop
%></select>

Although I know this is wrong, I'm going to put it here anyway so you can see what I really need:

<SELECT NAME="bhsunopen">
<%
Dim strSunapptframe
strSunapptframe = "30"
addTime = dateadd("H","0",strSunOpen)

Do While addTime <= dateadd("H","0",strSunClose)
addTime = DateAdd("n",strSunapptframe,addTime)
Response.Write "<OPTION VALUE=" & addTime & [RIGHT HERE: if objRS("bhsunopen")=addTime Then Response.Write "Selected"]">" & addTime & "</OPTION>"
Loop
%></select>

Is this possible? Any and all help is and will be greatly appreciated.
 
how about

Do While addTime <= dateadd("H","0",strSunClose)
addTime = DateAdd("n",strSunapptframe,addTime)
if objRS("bhsunopen")=addTime Then
strselect="Selected"
else
strselect=""
end if

Response.Write "<OPTION VALUE=""" & addTime & """ "&strselect&">" & addTime & "</OPTION>"

Loop
 
Hey Steven290! Thank you SO much for replying. I tried your code and it's not putting the "Selected" text in the Option code. The objRS("bhsunopen") does falls within the "addTime" results, but it's just not catching the SELECTED. Here's what it looks like when I view the source in HTML:

<OPTION VALUE=9:00:00 AM >9:00 AM</OPTION>

Any ideas?
 
loop through it but display both tell me what you get

Do While addTime <= dateadd("H","0",strSunClose)
addTime = DateAdd("n",strSunapptframe,addTime)

response.write objRS("bhsunopen")&"--"
response.write addTime &"<br>"


Loop

lets make sure one is matching
 
also is this what you getting

<OPTION VALUE=9:00:00 AM >9:00 AM</OPTION>

that can't be right, my code has quotes surround the value and the value and label don't match
 
This is what I'm getting from the last set of code you offered:

9:00:00 AM--8:30:00 AM
9:00:00 AM--9:00:00 AM
9:00:00 AM--9:30:00 AM
9:00:00 AM--10:00:00 AM
9:00:00 AM--10:30:00 AM
9:00:00 AM--11:00:00 AM
9:00:00 AM--11:30:00 AM
9:00:00 AM--12:00:00 PM
9:00:00 AM--12:30:00 PM
9:00:00 AM--1:00:00 PM
 
got it

Do While addTime <= dateadd("H","0",strSunClose)
addTime = DateAdd("n",strSunapptframe,addTime)
if cstr(objRS("bhsunopen"))=cstr(addTime) Then
strselect="Selected"
else
strselect=""
end if

Response.Write "<OPTION VALUE=""" & addTime & """ "&strselect&">" & addTime & "</OPTION>"

Loop
 
WOW! You saved me again! I am truly learning a great deal from you. Can you recommend any great books and/or tutorials. I NEVER would have came up with this solution.

You are awesome! Thanks again so much!
 
Glad it worked out for you. i would just try googling when ever you get suck .


remember those who helped you along the way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top