Solved

MULTIPLE 'AND' STATEMENT IN VBSCRIPT

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 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