Solved

VBScript Conditional Help

Posted on 2007-03-28
3
354 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Extracting nodes  using classical ASP 3 29
Convert this script to work with Windows 10 ftp 36 72
Html split(text) Part2 6 25
PHP $_POST vs asp request 4 28
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

730 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