Results 1 to 14 of 14

Thread: Check if 2 numbers are both between a certain range

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    19

    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:

    Code:
    '(' expected.
    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

  2. #2
    Lively Member
    Join Date
    Jun 2018
    Posts
    80

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    19

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by KBConsole View Post
    You're missing an "End If" start there,

    KBConsole
    Where am I missing one? I thought I had an End If

    edit: nevermind

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    19

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by KBConsole View Post
    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.

  5. #5
    Lively Member
    Join Date
    Jun 2018
    Posts
    80

    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

  6. #6
    Lively Member
    Join Date
    Jun 2018
    Posts
    80

    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    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:
    1. If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 Then
    2.     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:
    1. If CInt(OutputString(6)) >= -70 And CInt(OutputString(6)) <= -60 And
    2.    CInt(OutputString(5)) >= 15 And CInt(OutputString(5)) <= 20 Then
    You should also be using AndAlso rather than And.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,044

    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

  9. #9
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,140

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by Shaggy Hiker View Post
    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.

    Quote Originally Posted by jmcilhinney View Post
    You should also be using AndAlso rather than And.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by Shaggy Hiker View Post
    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?
    Quote Originally Posted by jmcilhinney View Post
    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.

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by jmcilhinney View Post
    ... 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.

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,044

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by jmcilhinney View Post
    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

  13. #13
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Check if 2 numbers are both between a certain range

    greater/= than -70 and also(no joke) = or less than -60?

  14. #14
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,541

    Re: Check if 2 numbers are both between a certain range

    Quote Originally Posted by ident View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Click Here to Expand Forum to Full Width