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!

How to Capture Loop Results 1

Status
Not open for further replies.

pupadu

Programmer
Mar 18, 2005
24
US
Hello everyone and anyone. I'm new to ASP and to this forum. So please bear with me. I have a Do While loop and need to know how to capture the results of the loop (which is displayed on the screen) into something like variables.

In other words:

LOOP RESULT

8:00 PM
9:00 PM

Should be able to store results in variables

var1 = 8:00 PM
var2 = 9:00 PM

Any and all help is appreciated.
 
what do you want to do with the variable, display it to the screen
 
Here's the original code of my working loop:

<%
Dim strSatOpen
Dim strSatClosed
Dim strSatapptframe
Dim addTime
Dim newTim

strSatOpen = ("08:00:00")
strSatClosed = ("17:00:00")
strSatapptframe = "30"
addTime = dateadd("H","0",strSatOpen)
response.write addtime

Do While addTime < dateadd("H","0",strSatclosed)
addTime = DateAdd("n",strSatapptframe,addTime)
Response.Write "<br>" & addTime
Loop
%>

What I want to do with the results is assign each output to a variable possibly. With these variables, I can compare their values to the data in a particular database field (MSSQL). If the variable value is equal to the database value, then that variable value should NOT display on the screen. I hope I explained it correctly. Otherwise, thanks for answering so quickly.
 
pupadu,

Assign them to a dynamic array.
[tt]
<%
Dim strSatOpen
Dim strSatClosed
Dim strSatapptframe
Dim addTime
Dim newTim

[blue]dim dt() : redim dt(-1)[/blue]

strSatOpen = ("08:00:00")
strSatClosed = ("17:00:00")
strSatapptframe = "30"
addTime = dateadd("h",cint("0"),strSatOpen)
response.write addtime

Do While addTime < dateadd("h",cint("0"),strSatclosed)
addTime = DateAdd("n",cint(strSatapptframe),addTime)
[blue]redim preserve dt(ubound(dt)+1)
dt(ubound(dt))=addTime[/blue]
Response.Write "<br>" & addTime
[blue]response.write replace(string(8," ")," ","&nbsp;") & dt(ubound(dt))[/blue]
Loop
%>
[/tt]
You have array dt() filed up for you to manipulate further.

regards - tsuji
 
Tsuji, THANK YOU, THANK YOU, THANK YOU!!! You and your programming skills are extremely appreciated. :) BTW, great forum, Tek-Tips.com!! Keep up the great work!
 
Okay. New problem, same script.

Thanks to Tsuji, the script works great (thanks again Tsuji!). I attempted to tweak it a little to see if I could take it a step further. Here's the code:

<%
Dim strSatOpen
Dim strSatClosed
Dim strSatapptframe
Dim addTime
Dim newTime
Dim whatTime

dim dt() : redim dt(-1)

strSatOpen = ("08:00:00")
strSatClosed = ("17:00:00")
strSatapptframe = "30"
addTime = dateadd("h",cint("0"),strSatOpen)
response.write addtime
newTime = ("09:00:00") 'this eventually would be data from a recordset
whatTime = dateadd("h",cint("0"),newTime)

Do While addTime < dateadd("h",cint("0"),strSatclosed)
addTime = DateAdd("n",cint(strSatapptframe),addTime)
redim preserve dt(ubound(dt)+1)
dt(ubound(dt))=addTime
If whatTime <> dt(ubound(dt)) Then
response.write replace(string(1," ")," ","<br>") & dt(ubound(dt))
End If
Loop
%>

It works fine. However, if I was to change the variable "newTime" to "08:00:00" or "08:30:00", these times continue to display when they shouldn't. Any ideas what I've done wrong?

Again, any and all help is greatly appreciated.
 
pupadu,

Time arithmetic is arithmetic of real number modulo computer limitation on binary representation of it. For real numbers, comparison of any two real number being = is of probability straightly zero (Lebesgue measure zero), and equivalently <> probability one. Hence, it is always ill-advised to compare real number as such.

In its representation, time 00:00:01 is 1/24/60/60, about 10^(-5). That is about the scale for comparison of time to that precision. To distinguish 00:00:05, the currency subtype would work exactly just fine.

So to make the script well-behaved to the precision of 00:00:05, change the line to this.
[tt]
If [blue]ccur[/blue](whatTime) <> [blue]ccur[/blue](dt(ubound(dt))) Then
[/tt]
As an aside, some of the turns I deviced are for illustration of certain aspect of thing, like cint("0") etc., hoping you pick up the significance. It may not straightly be necessary. In particular, the renderment of "<br>" in html is just fine without replace() etc I'd used for space. Hence, you should keep your original way, otherwise, it is unnecessarily clumsy.
[tt]
response.write "<br>" & dt(ubound(dt))
[/tt]
- tsuji
 
TSUJI, you are amazing! I'm learning so much just from your help. Being a newbie, I never would have caught on to that solution. Again, thank you so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top