Solved

Help with if statement

Posted on 2006-07-07
5
246 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

15 Experts available now in Live!

Get 1:1 Help Now