Solved

Help with if statement

Posted on 2006-07-07
5
251 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, CISSP
[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, CISSP
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, CISSP
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

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