Solved

MULTIPLE 'AND' STATEMENT IN VBSCRIPT

Posted on 2006-07-22
4
285 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
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
Comment Utility
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
Comment Utility
What did you do?  They look identical...?  lol
0
 

Author Comment

by:MoJeaux39
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

728 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

12 Experts available now in Live!

Get 1:1 Help Now