AND / OR functionality (or lack thereafter...)

Results 1 to 3 of 3

Thread: AND / OR functionality (or lack thereafter...)

  1. #1
    Karl Guest

    Default AND / OR functionality (or lack thereafter...)

    Is it just me or is the AND / OR functionality in ASP limited? Even though the falsehood, or truth, is known, the expressions will still be examined which might result in an error.<BR><BR>For example:<BR><BR> do while NOT Rs.EOF and myID = Rs("ID")<BR><BR>the above line will result in an error. Why? Because once Rs.EOF = TRUE, the &#039"myID = Rs("ID")&#039 will result in an error because we are at the end of file and therefore Rs("ID") is an error. To some of you, this might make a lot of might even think my do-loop is poorly structured because of it. But for anyone who&#039s programmed in a programming language (as opposed to a scripting language) you probably know how invaluable it is to know that as soon as the truth or falsehood of your statement is determined, the rest will not be examined (it&#039s also a lot more effecient).<BR><BR>Simple boolean logic here. For an AND expression to evaluate to true, all statements must be true ( if (x = 1 AND w = 1 AND z = 1) then...) ALL of those must be true in order for the if statement to be true. Therefore, as soon as you discover that w is NOT equal to 1, there should be no need (and there isn&#039t) to evaluate z = 1.<BR><BR>The same thing with an OR. as soon as 1 statement has been evaluated to true, the other statements need not be evaluated...the expression is true.<BR><BR>The work around to the do loop I put up is as follows:<BR><BR>dim flagstop = 1<BR>do while not rs.eof and flagstop = 1<BR> (...bunch of code here...)<BR>rs.movenext<BR>if not rs.eof<BR> if NOT myID = rs("id")<BR> FlagStop = 0<BR> end if<BR>end if<BR>LOOP<BR><BR>BOOOOYAAAA..that&#039s horrible.<BR><BR>Now that I&#039m done there a way to do what I&#039m trying to do? I don&#039t want alternatives to my long code...I want to make AND&#039s and OR&#039s work the way they are supposed to.<BR><BR>Thanks,<BR>Karl

  2. #2
    Join Date
    Dec 1969

    Default No idea if this is right, but just a tip...

    Tricky one. I&#039ve never noticed that difference before and your right that it should be the way that the AND and OR statements "should" work. the only thing I did notice is the lack of () around the statements. I alway use them, I don&#039t know if this makes a different but it might be worth trying it to see. As far as my mental model of the way ASP works if I stick brackets around all the different parts of any AND or OR statements then it knows they are seperate. I think that makes sense. Any way here&#039s what I mean:<BR><BR>If (X=1) AND ((Y&#062;0) OR (Z=2)) Then<BR><BR>Be interesting to see what others think?<BR><BR>Pete

  3. #3
    Karl Guest

    Default RE: No idea if this is right, but just a tip...

    It still wouldn&#039t work. But I agree it&#039s good practice to have expressions seperated within ( )..especially if you do a lot of programming in another language which requires it (like most). VB, and therefore VBScript, are quite relaxed with such thing..probably why some many people program in it...I didn&#039t include them &#039cuz it didn&#039t matter, but I to prefer to use them..&#039cuz if I don&#039t I&#039ll get a bunch of compiler errors in c++ next time I write something.<BR><BR>On a side note, someone might be wondering why I didn&#039t structure my query with a "...WHERE ID = " & myID) which would have seemingly eliminated my need to verify that my recordset is within a set parameter. Of course, the reason I don&#039t do this, is because the do-loop you see is a nested loop (hence the rest of the RS is used elsewhere). sure I could take another trip to the database and hit the server again...but that seems even LESS efficient than my use of if statements.<BR><BR>--<BR>Karl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts