Solved

VBScript Conditional Help

Posted on 2007-03-28
3
348 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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…

948 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

20 Experts available now in Live!

Get 1:1 Help Now