Solved

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

Posted on 2003-11-25
3
1,366 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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