[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VBScript Conditional Help

Posted on 2007-03-28
3
Medium Priority
?
363 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 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