Solved

Help with if statement

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 40
VB.Net Report Printing Issue 3 32
VB: Convert 2 dates to specific format 24 48
Sql server, import complete table, using vb.net 9 34
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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