?
Solved

MULTIPLE 'AND' STATEMENT IN VBSCRIPT

Posted on 2006-07-22
4
Medium Priority
?
328 Views
Last Modified: 2013-11-13
HI GUYS,
I need to compare 3 variables in one statement to see if they are all set to zero, if they are, alert the end user that one needs to be checked, other wise proceed with the script.  When I use more than one AND in an IF/then statement, it throws an error.  Any suggestions?  I'm assigning a high pt value because the question is urgent.  Thank you for your time!

Here's a sample of the if then statement I tried use initially which caused the error:

If (form79) = 0 And (form80) = 0 And (form81) = 0 Then
      MsgBox ("CAN NOT CONTINUE - MISSING BANK RESULTS -CHECK ONE OF THE BOXES")
      Exit Sub
      ElseIf (Form79) = -1 And (Form80) = -1 Then
      MsgBox ("CAN NOT CONTINUE - RECHECK BANK RESULTS -ONLY CHECK ONE OF THE BOXES")
      Exit Sub
      ElseIf (Form79) = -1 And (Form81) = -1 Then
      MsgBox ("CAN NOT CONTINUE - RECHECK BANK RESULTS -ONLY CHECK ONE OF THE BOXES")
      Exit Sub
      ElseIf (Form80) = -1 And (Form81) = -1 Then
      MsgBox ("CAN NOT CONTINUE - RECHECK BANK RESULTS -ONLY CHECK ONE OF THE BOXES")
      Exit Sub
      ElseIf (Form79) = -1 Then
        (Form81) = 0
        (Form80) = 0
      ElseIf (Form80) = -1 Then
        (Form79) = 0
        (Form81) = 0
      ElseIf (Form81) = -1 Then
        (Form79) = 0
        (Form80) = 0
      Else
          If main.SCHKHIT.Checked Then
               form79 = -1
               Else
               form79 = 0
               End If
           If main.SCHKNF.Checked Then
              form80 = -1
              Else
              form80 = 0
              End If
          If main.SCHKCLR.Checked Then
             form81 = -1
             Else
             form81 = 0
             End If      
 End If
0
Comment
Question by:MoJeaux39
[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
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 1500 total points
ID: 17160243
Try it this way:

If (form79) = 0 And (form80) = 0 And (form81) = 0 Then
     MsgBox ("CAN NOT CONTINUE - MISSING BANK RESULTS -CHECK ONE OF THE BOXES")
     Exit Sub
      ElseIf (Form79) = -1 And (Form80) = -1 Then
     MsgBox ("CAN NOT CONTINUE - RECHECK BANK RESULTS -ONLY CHECK ONE OF THE BOXES")
     Exit Sub
      ElseIf (Form79) = -1 And (Form81) = -1 Then
     MsgBox ("CAN NOT CONTINUE - RECHECK BANK RESULTS -ONLY CHECK ONE OF THE BOXES")
     Exit Sub
      ElseIf (Form80) = -1 And (Form81) = -1 Then
     MsgBox ("CAN NOT CONTINUE - RECHECK BANK RESULTS -ONLY CHECK ONE OF THE BOXES")
     Exit Sub
      ElseIf (Form79) = -1 Then
        Form81 = 0
        Form80 = 0
      ElseIf (Form80) = -1 Then
        Form79 = 0
        Form81 = 0
      ElseIf (Form81) = -1 Then
        Form79 = 0
        Form80 = 0
      Else
          If main.SCHKHIT.Checked Then
               form79 = -1
               Else
               form79 = 0
               End If
           If main.SCHKNF.Checked Then
              form80 = -1
              Else
              form80 = 0
              End If
          If main.SCHKCLR.Checked Then
             form81 = -1
             Else
             form81 = 0
             End If    
 End If

0
 

Author Comment

by:MoJeaux39
ID: 17160340
What did you do?  They look identical...?  lol
0
 

Author Comment

by:MoJeaux39
ID: 17160402
It's working!... but I'm not sure why.  I compared the two scripts and they look the same.  Thank you for your time and solution!!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17161322
Look more closely, compare:

      ElseIf (Form79) = -1 Then
        (Form81) = 0
        (Form80) = 0
      ElseIf (Form80) = -1 Then
        (Form79) = 0
        (Form81) = 0
      ElseIf (Form81) = -1 Then
        (Form79) = 0
        (Form80) = 0

To:

     ElseIf (Form79) = -1 Then
        Form81 = 0
        Form80 = 0
      ElseIf (Form80) = -1 Then
        Form79 = 0
        Form81 = 0
      ElseIf (Form81) = -1 Then
        Form79 = 0
        Form80 = 0
0

Featured Post

Independent Software Vendors: 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 designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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

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