Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now