?
Solved

VBScript Conditional Help

Posted on 2007-03-28
3
Medium Priority
?
360 Views
Last Modified: 2008-01-09
I created what I would consider a straight foward conditional statement with multiple conditions but it appears to be much more complex than i expected as it's not returning the correct results.  This is in VBScript so that may be why the logic isn't responding as I would have expected.

dim c200, w200, c500, w500
c200 = CheckRegKSvc(regKvals, "200", "C") 'will return a 1
w200 = CheckRegKSvc(regKvals, "200", "W") 'will return a 0
c500 = CheckRegKSvc(regKvals, "500", "C") 'will return a 1
w500 = CheckRegKSvc(regKvals, "500", "W") 'will return a 0

if  (c200 = 1 or w200 = 1) and _
    (c500 = 1 or w500 = 1) then
      Call msgbox("Yes!")
else
      Call msgbox("No!")
end if

'--------- the function above responds with a yes

if (CheckRegKSvc(regKvals, "200", "C") = 1 or CheckRegKSvc(regKvals, "200", "W")) = 1 and _
   (CheckRegKSvc(regKvals, "500", "C") = 1 or CheckRegKSvc(regKvals, "500", "W")) = 1 then
      Call msgbox("Yes!")
else
      Call msgbox("No!")
end if

'------------------this function responds with a no....


the only difference is i set the values to a variable and compare that variable and it responds as expected, when i try to put my function logic in the conditional it responds incorrectly...
0
Comment
Question by:jimtxas
[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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 2000 total points
ID: 18811286
Hi Jim,

I think it has to do with the positioning of your parenthesis. Currently you have the line:
if (CheckRegKSvc(regKvals, "200", "C") = 1 or CheckRegKSvc(regKvals, "200", "W")) = 1 and _
   (CheckRegKSvc(regKvals, "500", "C") = 1 or CheckRegKSvc(regKvals, "500", "W")) = 1 then

Try changing that to:
if (CheckRegKSvc(regKvals, "200", "C") = 1 or CheckRegKSvc(regKvals, "200", "W") = 1) and _
   (CheckRegKSvc(regKvals, "500", "C") = 1 or CheckRegKSvc(regKvals, "500", "W") = 1) then

I moved the parenthesis after the =1 for each of the 2nd conditions in the 'or' blocks.  Give it a try, should work as needed.
Matt
0
 

Author Comment

by:jimtxas
ID: 18811324
ouch... you're completly right.  I've been staring at it so long I don't think i would have ever caught that.  Fresh eyes are always good.  Thanks much!
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18811343
I hate that when you stare at something and work with something for so long that the little (normally easy) things just cant work. It is like writing/typing the same word so many times that it begins looking like it is spelled wrong :)
Let me know if you need anything else!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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/…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 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