wondering if there is a way to shorten up this IF statement i have going on..

If my.settings.id <> 1.001 or my.settings.id <> 2.001 or my.settings.id <> 3.001 then

do it like this

end if

what im looking for is a shorter way, i have tried

if my.settings.id <> (1.001 or 2.001 or 3.001) then

do it like this

end if

but it didn't work out for me.


thanks in advanced.

Dim value As Integer = 6

        Select Case value
            Case 1, 2, 3
                MessageBox.Show("Blah")
            Case Else
                MessageBox.Show("Errr")
        End Select

true.

what do you think about this

If (My.Settings.Security_Profile <> (1.001) And (8.001) And (1.001) And (13.001) And (9.001) And (99.0) And (1.001) And (2.001) And (5.001) And (6.001)) OrElse My.Settings.UserID <> dblUser_ID# Then

Don't like it.

If you're deadset on using an if statement instead of select case block, you can do something like this.

Dim value As Integer = 3
        Dim acceptedValues() As Integer = New Integer() {1, 2, 3}

        If acceptedValues.Contains(value) Then
            MessageBox.Show("Blah")
        Else
            MessageBox.Show("Errr")
        End If

no i didnt like it either

select case works much better and is easier to read

since i started it i also wanted to know the correct way to use the if statement as well.


thanks for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.