-
Jun 15th, 2018, 09:28 AM
#1
Thread Starter
Junior Member
Check if 2 numbers are both between a certain range
I need to check if the Lat/Long are both between a range. I had the Latitude figured out, but when I added the "And" statement for the Longitude, I keep getting an error:
Here's the code:
Code:
If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 And
If CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
CurrentAirspace.Text = "Gander FIR"
End If
-
Jun 15th, 2018, 09:36 AM
#2
Lively Member
Re: Check if 2 numbers are both between a certain range
You're missing an "End If" start there.
Also:
Code:
If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 And If CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
KBConsole
-
Jun 15th, 2018, 09:38 AM
#3
Thread Starter
Junior Member
Re: Check if 2 numbers are both between a certain range
Originally Posted by KBConsole
You're missing an "End If" start there,
KBConsole
Where am I missing one? I thought I had an End If
edit: nevermind
-
Jun 15th, 2018, 09:41 AM
#4
Thread Starter
Junior Member
Re: Check if 2 numbers are both between a certain range
Originally Posted by KBConsole
You're missing an "End If" start there.
Also:
Code:
If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 And If CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
KBConsole
I tried this and it's still giving me the error.
-
Jun 15th, 2018, 09:41 AM
#5
Lively Member
Re: Check if 2 numbers are both between a certain range
Looking at the "And" you put there I think you only wanted one "If/End If" therefore just remove the second if statement.
KBConsole
-
Jun 15th, 2018, 09:44 AM
#6
Lively Member
Re: Check if 2 numbers are both between a certain range
This should be what your code looks like once fixed:
Code:
If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 And
CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
CurrentAirspace.Text = "Gander FIR"
End If
If anything else comes up don't hesitate,
KBConsole
-
Jun 15th, 2018, 09:45 AM
#7
Re: Check if 2 numbers are both between a certain range
You need to decide whether you want one If statement or two. You've gone for six of one and half a dozen of the other. If you want two If statements then they both have to end with Then.
vb.net Code:
If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 Then
If CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
and you also need two End If statements. If you want one then you only use one If keyword:
vb.net Code:
If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 And
CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
You should also be using AndAlso rather than And.
-
Jun 15th, 2018, 11:23 AM
#8
Re: Check if 2 numbers are both between a certain range
Since nobody else mentioned it, let me also add that you should be using AndAlso rather than And. If you use And, then both expressions have to be evaluated, even if the first one is false. If the first one is false, it doesn't matter what the second one is, as the whole condition must be false. AndAlso will stop evaluating once the truth of the whole expression is known, while And requires that all parts are evaluated, needed or not.
My usual boring signature: Nothing
-
Jun 15th, 2018, 11:33 AM
#9
Re: Check if 2 numbers are both between a certain range
Originally Posted by Shaggy Hiker
Since nobody else mentioned it, let me also add that you should be using AndAlso rather than And. If you use And, then both expressions have to be evaluated, even if the first one is false. If the first one is false, it doesn't matter what the second one is, as the whole condition must be false. AndAlso will stop evaluating once the truth of the whole expression is known, while And requires that all parts are evaluated, needed or not.
It was mentioned.
Originally Posted by jmcilhinney
You should also be using AndAlso rather than And.
-
Jun 15th, 2018, 11:35 AM
#10
Re: Check if 2 numbers are both between a certain range
Originally Posted by Shaggy Hiker
Since nobody else mentioned it, let me also add that you should be using AndAlso rather than And.
Hey! Who are you calling "nobody" Mr?
Originally Posted by jmcilhinney
You should also be using AndAlso rather than And.
I'll let you off, given that that was the last line in the last post and someone your age must surely get tired out before getting that far.
-
Jun 15th, 2018, 11:57 AM
#11
Re: Check if 2 numbers are both between a certain range
Originally Posted by jmcilhinney
... someone your age must surely get tired out before getting that far.
Probably not so much a matter of stamina, as it is a matter of speed. Your post probably wasn't there when he started reading the thread about an hour and 1/2 earlier.
-
Jun 15th, 2018, 02:18 PM
#12
Re: Check if 2 numbers are both between a certain range
Originally Posted by jmcilhinney
Hey! Who are you calling "nobody" Mr?
I'll let you off, given that that was the last line in the last post and someone your age must surely get tired out before getting that far.
Yeah, if it goes beyond five words, or so, I need to take a nap. I'm back now, though.
My usual boring signature: Nothing
-
Jun 15th, 2018, 06:31 PM
#13
Re: Check if 2 numbers are both between a certain range
greater/= than -70 and also(no joke) = or less than -60?
-
Jun 15th, 2018, 09:11 PM
#14
Re: Check if 2 numbers are both between a certain range
Originally Posted by ident
greater/= than -70 and also(no joke) = or less than -60?
Yes... since they are negative numbers, -70 is less than -60... so the range being checked for is -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60
-tg
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
|