Results 1 to 9 of 9

Thread: [RESOLVED] detect user country from regional settings

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Resolved [RESOLVED] detect user country from regional settings

    Hello there -
    I've searched around but can't find a clear answer for this. From my winforms VB2010 app, I'd like to be able to detect the country of the user's PC at runtime. Specifically, all I really need to detect is whether the user is in Australia or Canada.

    Most things I've seen will say "have a look at System.Globalization.CultureInfo", but with no clear example. I also know that the old-school "GetLocaleInfo" API can be used for this as well. I do have some code using the latter, which detects Australia when LOCALE_ICOUNTRY returns a value of 61. However, that won't work for Canada, as it returns 1, which is the same as USA (I know that these are based on telephone country codes).

    Anyway, ideally, I'd like to be able to use the .NET Globalization class to detect both - but if I have to use the GetLocaleInfo API that's fine - I'll take what I can get - at the very least, I'd like an example of how I can detect Canada.

    Any help on this is greatly appreciated ...
    Last edited by BruceG; Jul 25th, 2011 at 07:18 AM. Reason: resolved
    "It's cold gin time again ..."

    Check out my website here.

  2. #2

    Re: detect user country from regional settings

    Why not just have the program ask? I guess if you want to try and do it automatically, that's fine but is there a problem asking?

  3. #3

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: detect user country from regional settings

    The app has to do it automatically (without user intervention), as it sets various labels and formats based on country.
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Re: detect user country from regional settings

    Maybe using an IP address to verify the location? I know there are various sites that allow you to do a location check via an IP address...but that seems too hard. Perhaps timezone checking?

    Do you need to only worry about Canada and Australia, or are other countries included as well?

  5. #5

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: detect user country from regional settings

    I only need to worry about Australia and Canada for the moment. Again, I'd like to do it through the PC's regional settings. I do have the old-school code to detect Australia, but as stated before, that same code is no good for Canada, as it shares the same country code with the US.
    "It's cold gin time again ..."

    Check out my website here.

  6. #6

    Re: detect user country from regional settings

    Well, the only option you could suggest is making a notice asking when it detects the US country code, to ask if they're in Canada as well. What exactly is this application supposed to do anyway?

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: detect user country from regional settings

    Not sure if this will be of any use.

    Edit:

    I found this which might give you some more information on the subject.
    Last edited by Nightwalker83; Jul 24th, 2011 at 08:06 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Resolved RESOLVED detect user country from regional settings

    Nightwalker - you were on the right track. With further research, I came up with my solution:
    Code:
    Select Case System.Globalization.CultureInfo.CurrentCulture.ToString
        Case "en-AU"
            ' this is Australia
        Case "en-CA", "fr-CA"
            ' this is Canada
    End Select
    I found the list of culture names here:
    http://msdn.microsoft.com/en-us/libr...fo(VS.80).aspx
    Last edited by BruceG; Jul 24th, 2011 at 08:55 PM. Reason: resoloved
    "It's cold gin time again ..."

    Check out my website here.

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: RESOLVED detect user country from regional settings

    Quote Originally Posted by BruceG View Post
    Nightwalker - you were on the right track. With further research, I came up with my solution:
    Glad I could be of some help. Also, to mark a thread resolved you need to edit the the title of the first post rather than the current post.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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