Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-25
3
Medium Priority
?
1,375 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 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