# Thread: [RESOLVED] If Not Statement for second statement doesnt work

1. ## [RESOLVED] If Not Statement for second statement doesnt work

I want to combine following two codes.

Code:
```If Not 11 < 10 Then
MessageBox.Show("Hello")
End If```
Code:
```If Not 22 < 20 Then
MessageBox.Show("Hello")
End If```
Why If Not doesnt work for second condition?

Code:
```If Not 11 < 10 And 22 < 20 Then
MessageBox.Show("Hello")
End If```

P.S.= Using If Not is mandatory. So, please dont advice me other solutions.

2. ## Re: If Not Statement for second statement doesnt work

Because you aren't properly combining the two If statements. The inclusion of Not in front only applies to the 11 < 10 comparison, the 22 < 20 is evaluated exactly as-is, without the Not. So it turns into:

If Not False And False, which results in False. So, you would need to do something like this:

Code:
`If Not 11 < 10 And Not 22 < 20 Then`

3. ## Re: If Not Statement for second statement doesnt work

both of these methods should work...

Code:
```If Not (11 < 10 And 22 < 20) Then
MessageBox.Show("Hello")
End If```
Code:
```If Not 11 < 10 And Not 22 < 20 Then
MessageBox.Show("Hello")
End If```

6. ## Re: [RESOLVED] If Not Statement for second statement doesnt work

It won't make a difference to the end result in this case but that code should also be using AndAlso rather than And. AndAlso and OrElse should be the default options because they short-circuit and the And and Or operators should only be used when you specifically don't want short-circuiting, which should be very rare.

7. ## Re: [RESOLVED] If Not Statement for second statement doesnt work

@jmcilhinney Do you have another solution?

8. ## Re: [RESOLVED] If Not Statement for second statement doesnt work

Originally Posted by Kram Kramer
@jmcilhinney Do you have another solution?
It works...

9. ## Re: [RESOLVED] If Not Statement for second statement doesnt work

Originally Posted by Kram Kramer
@jmcilhinney Do you have another solution?
What's wrong with the two options you already have?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured