Solved

MULTIPLE 'AND' STATEMENT IN VBSCRIPT

Posted on 2006-07-22
4
311 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to set the row selection as it was prior leaving the datagrid in vb6 3 48
Passing a Text Box name to a Sub 6 99
ruby gem installation 2 53
VB6 ListBox Question 4 48
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

809 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