Solved

ASP: VBScript condition evaluation checks every condition even if one already is false!

Posted on 2003-11-25
3
1,360 Views
Last Modified: 2008-03-10
Why is it that in vbscript (in my asp page) the condition evaluation will check every single condition in the statement even tho it already found one that is false!?!?!?

This applies to "If" and "Do While" statements as far as I have seen.

How do I go about making it stop evaluating as soon as it arrives at a false statement.

Example (oConn is a connection to db that was established earlier):
Dim oRs
Set oRs = Server.CreateObject("ADODB.RECORDSET")
oRs.CursorLocation = 2 'use server supplied cursor
oRs.ActiveConnection = oConn

oRs.open("SELECT some_field FROM some_table")

Do While Not oRs.EOF And oRs("some_field") = "some value"
    ...
Loop

Even once oRs reaches EOF it attempts to evaluate the check if oRs("some_field") = "some value" and the entire asp dies saying:

Exception occurred.

/some/script.asp, line 316

Line 316 is the 'Do While...' line.
0
Comment
Question by:robysath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 9820508
Do While Not oRs.EOF
if oRs("some_field") = "some value" then
Exit Do
end if
Loop
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 100 total points
ID: 9820527
@robysath:

> Why is it that in vbscript (in my asp page) the condition evaluation will
> check every single condition in the statement even tho it already found one
> that is false!?!?!?

> This applies to "If" and "Do While" statements as far as I have seen.

> How do I go about making it stop evaluating as soon as it arrives at a false statement.

You don't.  That's just how VB does it.  In C/C++, it stops evaluating as soon as it finds one false statement, but that just isn't true in VB.  I suggest you modify your code slightly to account for this:

    Do While Not oRs.EOF
        If ( oRs("some_field") <> "some value" ) Then
              Exit Do
        End If

        ...
    Loop

Yeah, it isn't as clean as what you originally wrote, but that's VB for ya.

Hope That Helps,
Dex*
0
 
LVL 1

Author Comment

by:robysath
ID: 9824778
Points go to Dexstar for answering all questions, thanks.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question