Solved

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

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rebind a grid after user clicks on node in treeview 1 35
Button to go back 3 25
Connecting to multiple databases to create a Dashboard 5 26
Select case on click 3 16
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 information …
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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