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

Do While not Statement

Ben
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenBase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveNext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
9 9097
Why've you got them in 2 DW loops?

Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If

'-----Figures out how they heard about the program

If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext
Loop

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Ben" <Be************@langley.af.mil> wrote in message
news:#j**************@tk2msftngp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenBase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveNext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #2
Why do you need to perform the loop twice? One problem is that in your
first loop, you move to the EOF. When you start your second loop, you're
already at EOF, so where is it supposed to go? The Do never enters...

Isn't this simply re-written as:

do while not rs.eof
' do stuff from first loop
' do stuff from second loop
rs.movenext
loop

You should also review http://www.aspfaq.com/2191 ... I see no reason for
ADODB.Recordset here.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ben" <Be************@langley.af.mil> wrote in message
news:#j**************@tk2msftngp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenBase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveNext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #3
Previous responses provided a better solution... and Aaron hints as to why
the second loop returns nothing. That being said..and noting that *I* would
use the aformentioned solutions.. to answer your specific question; to make
your code work add rs_Report.Movefirst prior to starting the second loop.


"Ben" <Be************@langley.af.mil> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenBase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveNext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4
How about just doing a count query or queries?
intMale = odoCon.Execute("SELECT COUNT(gender) FROM tblUsers WHERE
gender='male'").Fields.Item(0).Value
intFemale = odoCon.Execute("SELECT COUNT(gender) FROM tblUsers WHERE
gender='female'").Fields.Item(0).Value
intBasePaper = odoCon.Execute("SELECT COUNT(referral) FROM tblUsers WHERE
referral='Base Paper'").Fields.Item(0).Value

(Some would argue against the methods above, however.)

For sexes, you could also do "SELECT gender,COUNT(gender) FROM tblUsers
GROUP BY gender ORDER BY gender" to gram male and female at once.

Ray at work


"Ben" <Be************@langley.af.mil> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenBase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveNext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #5
Depending on the database and version, you can probably do this in one
query, returning one row, and eliminating the need to loop at all, never
mind multiple times.

For SQL Server:

SELECT
male = SUM(CASE gender WHEN 'male' THEN 1 ELSE 0 END),
female = SUM(CASE gender WHEN 'female' THEN 1 ELSE 0 END),
basePaper = SUM(CASE referral WHEN 'Base Paper' THEN 1 ELSE 0 END)
FROM tblUsers

I'm continually amazed that people think it is too much work, or not
valuable enough, to include what type of database they are working with...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:OW**************@TK2MSFTNGP09.phx.gbl...
How about just doing a count query or queries?
intMale = odoCon.Execute("SELECT COUNT(gender) FROM tblUsers WHERE
gender='male'").Fields.Item(0).Value
intFemale = odoCon.Execute("SELECT COUNT(gender) FROM tblUsers WHERE
gender='female'").Fields.Item(0).Value
intBasePaper = odoCon.Execute("SELECT COUNT(referral) FROM tblUsers WHERE
referral='Base Paper'").Fields.Item(0).Value

(Some would argue against the methods above, however.)

For sexes, you could also do "SELECT gender,COUNT(gender) FROM tblUsers
GROUP BY gender ORDER BY gender" to gram male and female at once.

Ray at work


"Ben" <Be************@langley.af.mil> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have two 'Do While Not' statements, that are getting information from
the same recordset. If I comment out the first one I can get the results
for the second one, and vice-versa. Why is this happening? Is it because
it's already at the EOF? If so how do I get it back to the BOF for the
2nd 'Do While Not' statement?

'----------------------------------------
'Create an ADO recordset object
Set rs_Report = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT gender, referral, youthmember, age FROM tblUsers WHERE
base = '" + Replace(chosenBase, "'", "''") + "'"

'Open the recordset with the SQL query
rs_Report.Open strSQL, adoCon

'-----Gets the total number of male and female users
intMale = 0
intFemale = 0
Do While NOT rs_Report.EOF
If rs_Report("gender") = "male" then
intMale = intMale + 1
Else
intFemale = intFemale + 1
End If
rs_Report.MoveNext()
Loop
'-----Figures out how they heard about the program

Do While NOT rs_Report.EOF
If rs_Report("referral") = "Base Paper" then
intBasePaper = intBasePaper + 1
End IF
rs_Report.MoveNext()
Loop
----------------------------------------------
--Sample Output--
Male = 11
Female = 4

Base Paper =__ "nothing is returned here"

----------------------------------------------
Like I said before If I comment out the first do while not statement I
can get the answers for the second one. If I don't it doesn't even get
inside of the second do while not statement.

I know I can fix it by just having a seperate SQL statement to the
database and get my information seperately, but it seems like a waste of
time. Thanks for any help.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 19 '05 #6
> I'm continually amazed that people think it is too much work, or not
valuable enough, to include what type of database they are working with...


http://www.aspfaq.com/5009
(There there, that feels better.)
Jul 19 '05 #7
Ben
>do while not rs.eof
' do stuff from first loop
' do stuff from second loop
rs.movenext
loop
Aaron: This is what Im going to end up doing, thanks for the insight, Im
still a beginner at this.
intMale = odoCon.Execute("SELECT COUNT(gender) FROM >tblUsers WHERE
gender='male'").Fields.Item(0).Value
intFemale = odoCon.Execute("SELECT COUNT(gender) FROM >tblUsers WHERE
gender='female'").Fields.Item(0).Value
intBasePaper = odoCon.Execute("SELECT COUNT(referral) FROM >tblUsers WHEREreferral='Base Paper'").Fields.Item(0).Value
Ray: Why would some argue against this method?
I'm continually amazed that people think it is too much >work, or not
valuable enough, to include what type of database they are >working

with...

Aaron: Sorry about the oversight,it's an Access database until reading
the article I didn't realize that it was important, but now I know
better. Im still new to all of this(SQL, ASP, Access), so any help is
appreciated.

-=Ben
-=To email me take out the joke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #8
Ooh, and I didn't know about 5008. I like that one too. :]

Ray at home

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
http://www.aspfaq.com/5009
(There there, that feels better.)

Jul 19 '05 #9

"Ben" <Be************@langley.af.mil> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
intMale = odoCon.Execute("SELECT COUNT(gender) FROM >tblUsers WHERE
gender='male'").Fields.Item(0).Value
Ray: Why would some argue against this method?


The argument would come from doing this:

someValue = ADOObject.Execute("a query").Fields.Item(0).Value

as opposed to:

Set rs = ADOObject.Execute("a query")
someValue = rs.Fields.Item(0).Value
rs.Close
Set rs = Nothing
When you implicitly create an object as is done in code sample 1, that
object won't be destroyed until the ASP engine is finished processing the
whole page and is cleaning up. So, it is not the most efficient way of
doing things. You typically want to create your recordset (or any object),
just before you need it and close and destroy it as soon as you no longer
need it. Does this matter or will you notice a difference in page load
times? No. If you get to that point, you won't be using Access anymore
anyway. :]

Ray at home
Jul 19 '05 #10

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

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.