-
Jun 13th, 2018, 10:15 AM
#1
Thread Starter
Addicted Member
[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.
Last edited by Kram Kramer; Jun 13th, 2018 at 10:32 AM.
-
Jun 13th, 2018, 10:27 AM
#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
-
Jun 13th, 2018, 10:28 AM
#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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2018, 10:30 AM
#4
Thread Starter
Addicted Member
Re: If Not Statement for second statement doesnt work
Thanks a lot OptionBase1. Your answer is exact answer which I am looking for.
-
Jun 13th, 2018, 10:31 AM
#5
Thread Starter
Addicted Member
Re: If Not Statement for second statement doesnt work
Thanks a lot paul. Your answer is exact answer which I am looking for.
-
Jun 13th, 2018, 10:33 AM
#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.
-
Jun 13th, 2018, 10:36 AM
#7
Thread Starter
Addicted Member
Re: [RESOLVED] If Not Statement for second statement doesnt work
@jmcilhinney Do you have another solution?
-
Jun 13th, 2018, 10:43 AM
#8
Re: [RESOLVED] If Not Statement for second statement doesnt work
Originally Posted by Kram Kramer
@jmcilhinney Do you have another solution?
It works...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2018, 10:46 AM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|