Jump to content

Country Location


Fade91
 Share

Recommended Posts

This was just a simple project for myself but may be someone else will find it interesting.

 

#include <IE.au3>
#include <Array.au3>
#include <String.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Country = RegRead("HKEY_CURRENT_USER\Control Panel\International\", "sCountry")

$oIE = _IECreateEmbedded()
GUICreate("Country Test" , 300, 300, Default, Default, BitNOT($WS_MINIMIZEBOX) + $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN, $WS_EX_TOPMOST)
GUISetBkColor(0xFFFFFF)
$Txt = GUICtrlCreateLabel("Loading...Please Wait!", 0, 80, 300, 220, $SS_CENTER)
$Obj = GUICtrlCreateObj($oIE, 100, 0, 100, 80)
GUISetState(@SW_SHOW)
$Flag = _Short_Country($Country)
_IENavigate($oIE, "www.flagpedia.net/data/flags/mini/" & StringLower($Flag) & ".png")
$oIE.Document.Body.Scroll = "No"
$oIE.Document.Body.Style.Border = "0px"
GUICtrlSetState($Obj, $GUI_DISABLE)
$oIE_Read = _IECreate("www.flagpedia.net/" & StringLower($Country), 0, 0, 1, 0)
$oIE_String = _StringBetween(_IEBodyReadHTML($oIE_Read), "<p>", "</p>")
GUICtrlSetData($Txt, $oIE_String[0])

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _IEQuit($oIE)
            _IEQuit($oIE_Read)
            Exit
    EndSwitch
WEnd

Func _Short_Country($sCountry)
    Local Enum $GEO_NATION = 0x0001, $GEO_LATITUDE, $GEO_LONGITUDE, $GEO_ISO2, $GEO_ISO3, $GEO_RFC1766, $GEO_LCID, $GEO_FRIENDLYNAME, $GEO_OFFICIALNAME, $GEO_TIMEZONES, $GEO_OFFICIALLANGUAGES, $GEO_ISO_UN_NUMBER, $GEO_PARENT
    Local $SC_Name, $aCall
    For $iGEOId = 0 To 0xFFFF
        $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_FRIENDLYNAME, "wstr", "", "int", 65536, "word", 0)
        If @error Then Return $SC_Name
        If $aCall[3] = $sCountry Then
            $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_ISO2, "wstr", "", "int", 65536, "word", 0)
            If @error Then Return $SC_Name
            $SC_Name = $aCall[3]
            ExitLoop
        EndIf
    Next
    Return $SC_Name
EndFunc

 

Edited by Fade91
Link to comment
Share on other sites

Get the same error here.
The problem is caused by the fact that the country is stored in the registry in the local language (e.g. Deutschland) but flagpedia needs the country name in English (e.g. Germany).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Well, this is what i got.

"XXXXXX\Desktop\Flag.au3" (30) : ==> Subscript used on non-accessible variable.:
GUICtrlSetData($Txt, $oIE_String[0])
GUICtrlSetData($Txt, $oIE_String^ ERROR
->21:58:03 AutoIt3.exe ended.rc:1

 

 000182.jpg

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@TheDcoder I am wondering that how the flag became us flag.  Infact i am in kerala and where is our tricolor ?. May be this program is a prank :)

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@kcvinu It is not a prank, Did forgot to change your language to English (India) while installing windows?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

May be.

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

12 minutes ago, kcvinu said:

Well, this is what i got.

"XXXXXX\Desktop\Flag.au3" (30) : ==> Subscript used on non-accessible variable.:
GUICtrlSetData($Txt, $oIE_String[0])
GUICtrlSetData($Txt, $oIE_String^ ERROR
->21:58:03 AutoIt3.exe ended.rc:1

 

should look for "http://flagpedia.net/the-united-states" but it looks for "http://www.flagpedia.net/united states"

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Anyway, i have changed the code little bit like this

$Flag = _Short_Country("India")
$oIE_Read = _IECreate("http://flagpedia.net/india", 0, 0, 1, 0)

Then i got my tricolor

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@kcvinu The path is hard coded, You can change your system locale instead :): http://windows.microsoft.com/en-us/windows/change-system-locale#1TC=windows-7

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

$Flag = _Short_Country($Country)

Local $aTemp = "", $sLink = ""
Local $sSource = _INetGetSource("http://flagpedia.net/index")
Local $aSource = StringSplit($sSource,@CRLF)
For $n = 1 To $aSource[0]
    If StringInStr($aSource[$n],'data/flags/mini/'& $Flag &'.png"') Then
        $aTemp = StringSplit($aSource[$n],'"')
        $sLink = "http://flagpedia.net"& $aTemp[4] ; use this for the link to get the text
        ExitLoop
    EndIf
Next

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Interesting, ill have to look into fixing it

[Edited]

I think if I switch the script to use this

HKEY_CURRENT_USER\Control Panel\International\iCountry

it would be a lot more accurate.

Edited by Fade91
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...