Solved

Help with if statement

Posted on 2006-07-07
5
250 Views
Last Modified: 2010-04-23
The following if statement is not working as expected in .NET

   If (MinLevel <> "2") Or (MinLevel <> "3") Or (MinLevel <> "4") Then
                        'this may be the first time thorough put up a messagebox
                        MsgBox("does not match 2, 3 or 4")

                    Else

Even though I see MinLevel = 2 it still says it does not match.  This worked in VB6 as above but I am looking for some insight on how to compare variable x with threee different numbers without having to

if then
elseif...


Thanks in advance for your assistance

-D-






0
Comment
Question by:John Gates
[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
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 17061500
If MinLevel is a numeric value then you need to drop the quotes. Also if you are checking that the value isn't 2, 3 or 4 then you probably want And rather than Or.

    If (MinLevel <> 2) And (MinLevel <> 3) And (MinLevel <> 4) Then
0
 
LVL 7

Expert Comment

by:davidrichardson
ID: 17061533
       If (MinLevel = "2") Or (MinLevel = "3") Or (MinLevel = "4") Then
            MsgBox("match")
        Else
            MsgBox("No Match")
        End If
0
 
LVL 17

Author Comment

by:John Gates
ID: 17061538
MinLevel is a string.  And I am checking if the value IS 2, 3 or 4

The above won't help.  Any ideas?
0
 
LVL 17

Author Comment

by:John Gates
ID: 17061572
here is the final and you were right....  (This program has my brain mushy 8)

If (MinLevel <> "2") And (MinLevel <> "3") And (MinLevel <> "4") Then



This is confusing for me coming from the VB6 world as all three things would have to return true for the above to work.  

Thanks!
0
 
LVL 7

Expert Comment

by:davidrichardson
ID: 17061575
?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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