Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

AutoIt Snippets


  • Please log in to reply
145 replies to this topic

#141 guestscripter

guestscripter

    Wayfarer

  • Active Members
  • Pip
  • 73 posts

Posted 12 January 2014 - 09:32 PM

Use to convert data from "Name = XXXX YYYY" to "Surname = YYY, First Name = XXXXXX" 

AutoIt         
  1. Local $sFullName = " Harry J T.  Potter"
  2. Local $aFirstnamesLast = splitfirstlastname($sFullName)
  3. ConsoleWrite($aFirstnamesLast[0] & @CR)
  4. ConsoleWrite($aFirstnamesLast[1] & @CR)
  5.  
  6. Func splitfirstlastname($sFullName)
  7.     Local $aWords = StringSplit(StringStripWS($sFullName, 7), " ");Clean out leading/trailing/double+ spaces, and Split into words
  8.     Local $sFirstnames, $sLastname
  9.     $sLastname = $aWords[$aWords[0]];Assume the last (or only) word is the last name
  10.     Select
  11.         Case $aWords[0] = 1;Assume no first name if only one word
  12.             $sFirstnames = ""
  13.         Case $aWords[0] = 2;If two words, assume this is the first and last name in that order
  14.             $sFirstnames = $aWords[1]
  15.         Case $aWords[0] > 2;If more than two words, all except the last are first names
  16.             For $n = 1 To $aWords[0] - 2
  17.                 $sFirstnames &= $aWords[$n] & " "
  18.             Next
  19.             $sFirstnames &= $aWords[$aWords[0] - 1]
  20.     EndSelect
  21.     Dim $aFirstnamesLast[] = [$sFirstnames, $sLastname]
  22.     Return $aFirstnamesLast
  23. EndFunc   ;==>splitfirstlastname








#142 guestscripter

guestscripter

    Wayfarer

  • Active Members
  • Pip
  • 73 posts

Posted 12 January 2014 - 10:26 PM

 Use to convert data that has country names to their corresponding 2-digit codes.

AutoIt         
  1.  
  2. Local $sCountry = "Fiji"
  3. ConsoleWrite("ISO Country Code: " & _CountryNameToISO($sCountry) & @CR)
  4.  
  5. Func _CountryNameToISO($sCountry)
  6.     Local $sCountryCode
  7.     ;names and codes according to
  8.     ;http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm
  9.     ;updated in December 2013
  10.     If $sCountry = "AFGHANISTAN" Then $sCountryCode = "AF"
  11.     If $sCountry = "ÅLAND ISLANDS" Then $sCountryCode = "AX"
  12.     If $sCountry = "ALBANIA" Then $sCountryCode = "AL"
  13.     If $sCountry = "ALGERIA" Then $sCountryCode = "DZ"
  14.     If $sCountry = "AMERICAN SAMOA" Then $sCountryCode = "AS"
  15.     If $sCountry = "ANDORRA" Then $sCountryCode = "AD"
  16.     If $sCountry = "ANGOLA" Then $sCountryCode = "AO"
  17.     If $sCountry = "ANGUILLA" Then $sCountryCode = "AI"
  18.     If $sCountry = "ANTARCTICA" Then $sCountryCode = "AQ"
  19.     If $sCountry = "ANTIGUA AND BARBUDA" Then $sCountryCode = "AG"
  20.     If $sCountry = "ARGENTINA" Then $sCountryCode = "AR"
  21.     If $sCountry = "ARMENIA" Then $sCountryCode = "AM"
  22.     If $sCountry = "ARUBA" Then $sCountryCode = "AW"
  23.     If $sCountry = "AUSTRALIA" Then $sCountryCode = "AU"
  24.     If $sCountry = "AUSTRIA" Then $sCountryCode = "AT"
  25.     If $sCountry = "AZERBAIJAN" Then $sCountryCode = "AZ"
  26.     If $sCountry = "BAHAMAS" Then $sCountryCode = "BS"
  27.     If $sCountry = "BAHRAIN" Then $sCountryCode = "BH"
  28.     If $sCountry = "BANGLADESH" Then $sCountryCode = "BD"
  29.     If $sCountry = "BARBADOS" Then $sCountryCode = "BB"
  30.     If $sCountry = "BELARUS" Then $sCountryCode = "BY"
  31.     If $sCountry = "BELGIUM" Then $sCountryCode = "BE"
  32.     If $sCountry = "BELIZE" Then $sCountryCode = "BZ"
  33.     If $sCountry = "BENIN" Then $sCountryCode = "BJ"
  34.     If $sCountry = "BERMUDA" Then $sCountryCode = "BM"
  35.     If $sCountry = "BHUTAN" Then $sCountryCode = "BT"
  36.     If $sCountry = "BOLIVIA, PLURINATIONAL STATE OF" Then $sCountryCode = "BO"
  37.     If $sCountry = "BONAIRE, SINT EUSTATIUS AND SABA" Then $sCountryCode = "BQ"
  38.     If $sCountry = "BOSNIA AND HERZEGOVINA" Then $sCountryCode = "BA"
  39.     If $sCountry = "BOTSWANA" Then $sCountryCode = "BW"
  40.     If $sCountry = "BOUVET ISLAND" Then $sCountryCode = "BV"
  41.     If $sCountry = "BRAZIL" Then $sCountryCode = "BR"
  42.     If $sCountry = "BRITISH INDIAN OCEAN TERRITORY" Then $sCountryCode = "IO"
  43.     If $sCountry = "BRUNEI DARUSSALAM" Then $sCountryCode = "BN"
  44.     If $sCountry = "BULGARIA" Then $sCountryCode = "BG"
  45.     If $sCountry = "BURKINA FASO" Then $sCountryCode = "BF"
  46.     If $sCountry = "BURUNDI" Then $sCountryCode = "BI"
  47.     If $sCountry = "CAMBODIA" Then $sCountryCode = "KH"
  48.     If $sCountry = "CAMEROON" Then $sCountryCode = "CM"
  49.     If $sCountry = "CANADA" Then $sCountryCode = "CA"
  50.     If $sCountry = "CAPE VERDE" Then $sCountryCode = "CV"
  51.     If $sCountry = "CAYMAN ISLANDS" Then $sCountryCode = "KY"
  52.     If $sCountry = "CENTRAL AFRICAN REPUBLIC" Then $sCountryCode = "CF"
  53.     If $sCountry = "CHAD" Then $sCountryCode = "TD"
  54.     If $sCountry = "CHILE" Then $sCountryCode = "CL"
  55.     If $sCountry = "CHINA" Then $sCountryCode = "CN"
  56.     If $sCountry = "CHRISTMAS ISLAND" Then $sCountryCode = "CX"
  57.     If $sCountry = "COCOS (KEELING) ISLANDS" Then $sCountryCode = "CC"
  58.     If $sCountry = "COLOMBIA" Then $sCountryCode = "CO"
  59.     If $sCountry = "COMOROS" Then $sCountryCode = "KM"
  60.     If $sCountry = "CONGO" Then $sCountryCode = "CG"
  61.     If $sCountry = "CONGO, THE DEMOCRATIC REPUBLIC OF THE" Then $sCountryCode = "CD"
  62.     If $sCountry = "COOK ISLANDS" Then $sCountryCode = "CK"
  63.     If $sCountry = "COSTA RICA" Then $sCountryCode = "CR"
  64.     If $sCountry = "CÔTE D'IVOIRE" Then $sCountryCode = "CI"
  65.     If $sCountry = "CROATIA" Then $sCountryCode = "HR"
  66.     If $sCountry = "CUBA" Then $sCountryCode = "CU"
  67.     If $sCountry = "CURAÇAO" Then $sCountryCode = "CW"
  68.     If $sCountry = "CYPRUS" Then $sCountryCode = "CY"
  69.     If $sCountry = "CZECH REPUBLIC" Then $sCountryCode = "CZ"
  70.     If $sCountry = "DENMARK" Then $sCountryCode = "DK"
  71.     If $sCountry = "DJIBOUTI" Then $sCountryCode = "DJ"
  72.     If $sCountry = "DOMINICA" Then $sCountryCode = "DM"
  73.     If $sCountry = "DOMINICAN REPUBLIC" Then $sCountryCode = "DO"
  74.     If $sCountry = "ECUADOR" Then $sCountryCode = "EC"
  75.     If $sCountry = "EGYPT" Then $sCountryCode = "EG"
  76.     If $sCountry = "EL SALVADOR" Then $sCountryCode = "SV"
  77.     If $sCountry = "EQUATORIAL GUINEA" Then $sCountryCode = "GQ"
  78.     If $sCountry = "ERITREA" Then $sCountryCode = "ER"
  79.     If $sCountry = "ESTONIA" Then $sCountryCode = "EE"
  80.     If $sCountry = "ETHIOPIA" Then $sCountryCode = "ET"
  81.     If $sCountry = "FALKLAND ISLANDS (MALVINAS)" Then $sCountryCode = "FK"
  82.     If $sCountry = "FAROE ISLANDS" Then $sCountryCode = "FO"
  83.     If $sCountry = "FIJI" Then $sCountryCode = "FJ"
  84.     If $sCountry = "FINLAND" Then $sCountryCode = "FI"
  85.     If $sCountry = "FRANCE" Then $sCountryCode = "FR"
  86.     If $sCountry = "FRENCH GUIANA" Then $sCountryCode = "GF"
  87.     If $sCountry = "FRENCH POLYNESIA" Then $sCountryCode = "PF"
  88.     If $sCountry = "FRENCH SOUTHERN TERRITORIES" Then $sCountryCode = "TF"
  89.     If $sCountry = "GABON" Then $sCountryCode = "GA"
  90.     If $sCountry = "GAMBIA" Then $sCountryCode = "GM"
  91.     If $sCountry = "GEORGIA" Then $sCountryCode = "GE"
  92.     If $sCountry = "GERMANY" Then $sCountryCode = "DE"
  93.     If $sCountry = "GHANA" Then $sCountryCode = "GH"
  94.     If $sCountry = "GIBRALTAR" Then $sCountryCode = "GI"
  95.     If $sCountry = "GREECE" Then $sCountryCode = "GR"
  96.     If $sCountry = "GREENLAND" Then $sCountryCode = "GL"
  97.     If $sCountry = "GRENADA" Then $sCountryCode = "GD"
  98.     If $sCountry = "GUADELOUPE" Then $sCountryCode = "GP"
  99.     If $sCountry = "GUAM" Then $sCountryCode = "GU"
  100.     If $sCountry = "GUATEMALA" Then $sCountryCode = "GT"
  101.     If $sCountry = "GUERNSEY" Then $sCountryCode = "GG"
  102.     If $sCountry = "GUINEA" Then $sCountryCode = "GN"
  103.     If $sCountry = "GUINEA-BISSAU" Then $sCountryCode = "GW"
  104.     If $sCountry = "GUYANA" Then $sCountryCode = "GY"
  105.     If $sCountry = "HAITI" Then $sCountryCode = "HT"
  106.     If $sCountry = "HEARD ISLAND AND MCDONALD ISLANDS" Then $sCountryCode = "HM"
  107.     If $sCountry = "HOLY SEE (VATICAN CITY STATE)" Then $sCountryCode = "VA"
  108.     If $sCountry = "HONDURAS" Then $sCountryCode = "HN"
  109.     If $sCountry = "HONG KONG" Then $sCountryCode = "HK"
  110.     If $sCountry = "HUNGARY" Then $sCountryCode = "HU"
  111.     If $sCountry = "ICELAND" Then $sCountryCode = "IS"
  112.     If $sCountry = "INDIA" Then $sCountryCode = "IN"
  113.     If $sCountry = "INDONESIA" Then $sCountryCode = "ID"
  114.     If $sCountry = "IRAN, ISLAMIC REPUBLIC OF" Then $sCountryCode = "IR"
  115.     If $sCountry = "IRAQ" Then $sCountryCode = "IQ"
  116.     If $sCountry = "IRELAND" Then $sCountryCode = "IE"
  117.     If $sCountry = "ISLE OF MAN" Then $sCountryCode = "IM"
  118.     If $sCountry = "ISRAEL" Then $sCountryCode = "IL"
  119.     If $sCountry = "ITALY" Then $sCountryCode = "IT"
  120.     If $sCountry = "JAMAICA" Then $sCountryCode = "JM"
  121.     If $sCountry = "JAPAN" Then $sCountryCode = "JP"
  122.     If $sCountry = "JERSEY" Then $sCountryCode = "JE"
  123.     If $sCountry = "JORDAN" Then $sCountryCode = "JO"
  124.     If $sCountry = "KAZAKHSTAN" Then $sCountryCode = "KZ"
  125.     If $sCountry = "KENYA" Then $sCountryCode = "KE"
  126.     If $sCountry = "KIRIBATI" Then $sCountryCode = "KI"
  127.     If $sCountry = "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF" Then $sCountryCode = "KP"
  128.     If $sCountry = "KOREA, REPUBLIC OF" Then $sCountryCode = "KR"
  129.     If $sCountry = "KUWAIT" Then $sCountryCode = "KW"
  130.     If $sCountry = "KYRGYZSTAN" Then $sCountryCode = "KG"
  131.     If $sCountry = "LAO PEOPLE'S DEMOCRATIC REPUBLIC" Then $sCountryCode = "LA"
  132.     If $sCountry = "LATVIA" Then $sCountryCode = "LV"
  133.     If $sCountry = "LEBANON" Then $sCountryCode = "LB"
  134.     If $sCountry = "LESOTHO" Then $sCountryCode = "LS"
  135.     If $sCountry = "LIBERIA" Then $sCountryCode = "LR"
  136.     If $sCountry = "LIBYA" Then $sCountryCode = "LY"
  137.     If $sCountry = "LIECHTENSTEIN" Then $sCountryCode = "LI"
  138.     If $sCountry = "LITHUANIA" Then $sCountryCode = "LT"
  139.     If $sCountry = "LUXEMBOURG" Then $sCountryCode = "LU"
  140.     If $sCountry = "MACAO" Then $sCountryCode = "MO"
  141.     If $sCountry = "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF" Then $sCountryCode = "MK"
  142.     If $sCountry = "MADAGASCAR" Then $sCountryCode = "MG"
  143.     If $sCountry = "MALAWI" Then $sCountryCode = "MW"
  144.     If $sCountry = "MALAYSIA" Then $sCountryCode = "MY"
  145.     If $sCountry = "MALDIVES" Then $sCountryCode = "MV"
  146.     If $sCountry = "MALI" Then $sCountryCode = "ML"
  147.     If $sCountry = "MALTA" Then $sCountryCode = "MT"
  148.     If $sCountry = "MARSHALL ISLANDS" Then $sCountryCode = "MH"
  149.     If $sCountry = "MARTINIQUE" Then $sCountryCode = "MQ"
  150.     If $sCountry = "MAURITANIA" Then $sCountryCode = "MR"
  151.     If $sCountry = "MAURITIUS" Then $sCountryCode = "MU"
  152.     If $sCountry = "MAYOTTE" Then $sCountryCode = "YT"
  153.     If $sCountry = "MEXICO" Then $sCountryCode = "MX"
  154.     If $sCountry = "MICRONESIA, FEDERATED STATES OF" Then $sCountryCode = "FM"
  155.     If $sCountry = "MOLDOVA, REPUBLIC OF" Then $sCountryCode = "MD"
  156.     If $sCountry = "MONACO" Then $sCountryCode = "MC"
  157.     If $sCountry = "MONGOLIA" Then $sCountryCode = "MN"
  158.     If $sCountry = "MONTENEGRO" Then $sCountryCode = "ME"
  159.     If $sCountry = "MONTSERRAT" Then $sCountryCode = "MS"
  160.     If $sCountry = "MOROCCO" Then $sCountryCode = "MA"
  161.     If $sCountry = "MOZAMBIQUE" Then $sCountryCode = "MZ"
  162.     If $sCountry = "MYANMAR" Then $sCountryCode = "MM"
  163.     If $sCountry = "NAMIBIA" Then $sCountryCode = "NA"
  164.     If $sCountry = "NAURU" Then $sCountryCode = "NR"
  165.     If $sCountry = "NEPAL" Then $sCountryCode = "NP"
  166.     If $sCountry = "NETHERLANDS" Then $sCountryCode = "NL"
  167.     If $sCountry = "NEW CALEDONIA" Then $sCountryCode = "NC"
  168.     If $sCountry = "NEW ZEALAND" Then $sCountryCode = "NZ"
  169.     If $sCountry = "NICARAGUA" Then $sCountryCode = "NI"
  170.     If $sCountry = "NIGER" Then $sCountryCode = "NE"
  171.     If $sCountry = "NIGERIA" Then $sCountryCode = "NG"
  172.     If $sCountry = "NIUE" Then $sCountryCode = "NU"
  173.     If $sCountry = "NORFOLK ISLAND" Then $sCountryCode = "NF"
  174.     If $sCountry = "NORTHERN MARIANA ISLANDS" Then $sCountryCode = "MP"
  175.     If $sCountry = "NORWAY" Then $sCountryCode = "NO"
  176.     If $sCountry = "OMAN" Then $sCountryCode = "OM"
  177.     If $sCountry = "PAKISTAN" Then $sCountryCode = "PK"
  178.     If $sCountry = "PALAU" Then $sCountryCode = "PW"
  179.     If $sCountry = "PALESTINE, STATE OF" Then $sCountryCode = "PS"
  180.     If $sCountry = "PANAMA" Then $sCountryCode = "PA"
  181.     If $sCountry = "PAPUA NEW GUINEA" Then $sCountryCode = "PG"
  182.     If $sCountry = "PARAGUAY" Then $sCountryCode = "PY"
  183.     If $sCountry = "PERU" Then $sCountryCode = "PE"
  184.     If $sCountry = "PHILIPPINES" Then $sCountryCode = "PH"
  185.     If $sCountry = "PITCAIRN" Then $sCountryCode = "PN"
  186.     If $sCountry = "POLAND" Then $sCountryCode = "PL"
  187.     If $sCountry = "PORTUGAL" Then $sCountryCode = "PT"
  188.     If $sCountry = "PUERTO RICO" Then $sCountryCode = "PR"
  189.     If $sCountry = "QATAR" Then $sCountryCode = "QA"
  190.     If $sCountry = "RÉUNION" Then $sCountryCode = "RE"
  191.     If $sCountry = "ROMANIA" Then $sCountryCode = "RO"
  192.     If $sCountry = "RUSSIAN FEDERATION" Then $sCountryCode = "RU"
  193.     If $sCountry = "RWANDA" Then $sCountryCode = "RW"
  194.     If $sCountry = "SAINT BARTHÉLEMY" Then $sCountryCode = "BL"
  195.     If $sCountry = "SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA" Then $sCountryCode = "SH"
  196.     If $sCountry = "SAINT KITTS AND NEVIS" Then $sCountryCode = "KN"
  197.     If $sCountry = "SAINT LUCIA" Then $sCountryCode = "LC"
  198.     If $sCountry = "SAINT MARTIN (FRENCH PART)" Then $sCountryCode = "MF"
  199.     If $sCountry = "SAINT PIERRE AND MIQUELON" Then $sCountryCode = "PM"
  200.     If $sCountry = "SAINT VINCENT AND THE GRENADINES" Then $sCountryCode = "VC"
  201.     If $sCountry = "SAMOA" Then $sCountryCode = "WS"
  202.     If $sCountry = "SAN MARINO" Then $sCountryCode = "SM"
  203.     If $sCountry = "SAO TOME AND PRINCIPE" Then $sCountryCode = "ST"
  204.     If $sCountry = "SAUDI ARABIA" Then $sCountryCode = "SA"
  205.     If $sCountry = "SENEGAL" Then $sCountryCode = "SN"
  206.     If $sCountry = "SERBIA" Then $sCountryCode = "RS"
  207.     If $sCountry = "SEYCHELLES" Then $sCountryCode = "SC"
  208.     If $sCountry = "SIERRA LEONE" Then $sCountryCode = "SL"
  209.     If $sCountry = "SINGAPORE" Then $sCountryCode = "SG"
  210.     If $sCountry = "SINT MAARTEN (DUTCH PART)" Then $sCountryCode = "SX"
  211.     If $sCountry = "SLOVAKIA" Then $sCountryCode = "SK"
  212.     If $sCountry = "SLOVENIA" Then $sCountryCode = "SI"
  213.     If $sCountry = "SOLOMON ISLANDS" Then $sCountryCode = "SB"
  214.     If $sCountry = "SOMALIA" Then $sCountryCode = "SO"
  215.     If $sCountry = "SOUTH AFRICA" Then $sCountryCode = "ZA"
  216.     If $sCountry = "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS" Then $sCountryCode = "GS"
  217.     If $sCountry = "SOUTH SUDAN" Then $sCountryCode = "SS"
  218.     If $sCountry = "SPAIN" Then $sCountryCode = "ES"
  219.     If $sCountry = "SRI LANKA" Then $sCountryCode = "LK"
  220.     If $sCountry = "SUDAN" Then $sCountryCode = "SD"
  221.     If $sCountry = "SURINAME" Then $sCountryCode = "SR"
  222.     If $sCountry = "SVALBARD AND JAN MAYEN" Then $sCountryCode = "SJ"
  223.     If $sCountry = "SWAZILAND" Then $sCountryCode = "SZ"
  224.     If $sCountry = "SWEDEN" Then $sCountryCode = "SE"
  225.     If $sCountry = "SWITZERLAND" Then $sCountryCode = "CH"
  226.     If $sCountry = "SYRIAN ARAB REPUBLIC" Then $sCountryCode = "SY"
  227.     If $sCountry = "TAIWAN, PROVINCE OF CHINA" Then $sCountryCode = "TW"
  228.     If $sCountry = "TAJIKISTAN" Then $sCountryCode = "TJ"
  229.     If $sCountry = "TANZANIA, UNITED REPUBLIC OF" Then $sCountryCode = "TZ"
  230.     If $sCountry = "THAILAND" Then $sCountryCode = "TH"
  231.     If $sCountry = "TIMOR-LESTE" Then $sCountryCode = "TL"
  232.     If $sCountry = "TOGO" Then $sCountryCode = "TG"
  233.     If $sCountry = "TOKELAU" Then $sCountryCode = "TK"
  234.     If $sCountry = "TONGA" Then $sCountryCode = "TO"
  235.     If $sCountry = "TRINIDAD AND TOBAGO" Then $sCountryCode = "TT"
  236.     If $sCountry = "TUNISIA" Then $sCountryCode = "TN"
  237.     If $sCountry = "TURKEY" Then $sCountryCode = "TR"
  238.     If $sCountry = "TURKMENISTAN" Then $sCountryCode = "TM"
  239.     If $sCountry = "TURKS AND CAICOS ISLANDS" Then $sCountryCode = "TC"
  240.     If $sCountry = "TUVALU" Then $sCountryCode = "TV"
  241.     If $sCountry = "UGANDA" Then $sCountryCode = "UG"
  242.     If $sCountry = "UKRAINE" Then $sCountryCode = "UA"
  243.     If $sCountry = "UNITED ARAB EMIRATES" Then $sCountryCode = "AE"
  244.     If $sCountry = "UNITED KINGDOM" Then $sCountryCode = "GB"
  245.     If $sCountry = "UNITED STATES" Then $sCountryCode = "US"
  246.     If $sCountry = "UNITED STATES MINOR OUTLYING ISLANDS" Then $sCountryCode = "UM"
  247.     If $sCountry = "URUGUAY" Then $sCountryCode = "UY"
  248.     If $sCountry = "UZBEKISTAN" Then $sCountryCode = "UZ"
  249.     If $sCountry = "VANUATU" Then $sCountryCode = "VU"
  250.     If $sCountry = "VENEZUELA, BOLIVARIAN REPUBLIC OF" Then $sCountryCode = "VE"
  251.     If $sCountry = "VIET NAM" Then $sCountryCode = "VN"
  252.     If $sCountry = "VIRGIN ISLANDS, BRITISH" Then $sCountryCode = "VG"
  253.     If $sCountry = "VIRGIN ISLANDS, U.S." Then $sCountryCode = "VI"
  254.     If $sCountry = "WALLIS AND FUTUNA" Then $sCountryCode = "WF"
  255.     If $sCountry = "WESTERN SAHARA" Then $sCountryCode = "EH"
  256.     If $sCountry = "YEMEN" Then $sCountryCode = "YE"
  257.     If $sCountry = "ZAMBIA" Then $sCountryCode = "ZM"
  258.     If $sCountry = "ZIMBABWE" Then $sCountryCode = "ZW"
  259.     Return $sCountryCode
  260. EndFunc   ;==>_CountryNameToISO


#143 rcmaehl

rcmaehl

    No where near a noob nor a pro coder.

  • Active Members
  • PipPipPipPipPipPip
  • 671 posts

Posted 24 February 2014 - 03:32 AM

 

 Use to convert data that has country names to their corresponding 2-digit codes.

AutoIt         
  1.  
  2. Local $sCountry = "Fiji"
  3. ConsoleWrite("ISO Country Code: " & _CountryNameToISO($sCountry) & @CR)
  4.  
  5. Func _CountryNameToISO($sCountry)
  6.     Local $sCountryCode
  7.     ;names and codes according to
  8.     ;http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm
  9.     ;updated in December 2013
  10.     If $sCountry = "AFGHANISTAN" Then $sCountryCode = "AF"
  11.     If $sCountry = "ÅLAND ISLANDS" Then $sCountryCode = "AX"
  12.     If $sCountry = "ALBANIA" Then $sCountryCode = "AL"
  13.     If $sCountry = "ALGERIA" Then $sCountryCode = "DZ"
  14.     If $sCountry = "AMERICAN SAMOA" Then $sCountryCode = "AS"
  15.     If $sCountry = "ANDORRA" Then $sCountryCode = "AD"
  16.     If $sCountry = "ANGOLA" Then $sCountryCode = "AO"
  17.     If $sCountry = "ANGUILLA" Then $sCountryCode = "AI"
  18.     If $sCountry = "ANTARCTICA" Then $sCountryCode = "AQ"
  19.     If $sCountry = "ANTIGUA AND BARBUDA" Then $sCountryCode = "AG"
  20.     If $sCountry = "ARGENTINA" Then $sCountryCode = "AR"
  21.     If $sCountry = "ARMENIA" Then $sCountryCode = "AM"
  22.     If $sCountry = "ARUBA" Then $sCountryCode = "AW"
  23.     If $sCountry = "AUSTRALIA" Then $sCountryCode = "AU"
  24.     If $sCountry = "AUSTRIA" Then $sCountryCode = "AT"
  25.     If $sCountry = "AZERBAIJAN" Then $sCountryCode = "AZ"
  26.     If $sCountry = "BAHAMAS" Then $sCountryCode = "BS"
  27.     If $sCountry = "BAHRAIN" Then $sCountryCode = "BH"
  28.     If $sCountry = "BANGLADESH" Then $sCountryCode = "BD"
  29.     If $sCountry = "BARBADOS" Then $sCountryCode = "BB"
  30.     If $sCountry = "BELARUS" Then $sCountryCode = "BY"
  31.     If $sCountry = "BELGIUM" Then $sCountryCode = "BE"
  32.     If $sCountry = "BELIZE" Then $sCountryCode = "BZ"
  33.     If $sCountry = "BENIN" Then $sCountryCode = "BJ"
  34.     If $sCountry = "BERMUDA" Then $sCountryCode = "BM"
  35.     If $sCountry = "BHUTAN" Then $sCountryCode = "BT"
  36.     If $sCountry = "BOLIVIA, PLURINATIONAL STATE OF" Then $sCountryCode = "BO"
  37.     If $sCountry = "BONAIRE, SINT EUSTATIUS AND SABA" Then $sCountryCode = "BQ"
  38.     If $sCountry = "BOSNIA AND HERZEGOVINA" Then $sCountryCode = "BA"
  39.     If $sCountry = "BOTSWANA" Then $sCountryCode = "BW"
  40.     If $sCountry = "BOUVET ISLAND" Then $sCountryCode = "BV"
  41.     If $sCountry = "BRAZIL" Then $sCountryCode = "BR"
  42.     If $sCountry = "BRITISH INDIAN OCEAN TERRITORY" Then $sCountryCode = "IO"
  43.     If $sCountry = "BRUNEI DARUSSALAM" Then $sCountryCode = "BN"
  44.     If $sCountry = "BULGARIA" Then $sCountryCode = "BG"
  45.     If $sCountry = "BURKINA FASO" Then $sCountryCode = "BF"
  46.     If $sCountry = "BURUNDI" Then $sCountryCode = "BI"
  47.     If $sCountry = "CAMBODIA" Then $sCountryCode = "KH"
  48.     If $sCountry = "CAMEROON" Then $sCountryCode = "CM"
  49.     If $sCountry = "CANADA" Then $sCountryCode = "CA"
  50.     If $sCountry = "CAPE VERDE" Then $sCountryCode = "CV"
  51.     If $sCountry = "CAYMAN ISLANDS" Then $sCountryCode = "KY"
  52.     If $sCountry = "CENTRAL AFRICAN REPUBLIC" Then $sCountryCode = "CF"
  53.     If $sCountry = "CHAD" Then $sCountryCode = "TD"
  54.     If $sCountry = "CHILE" Then $sCountryCode = "CL"
  55.     If $sCountry = "CHINA" Then $sCountryCode = "CN"
  56.     If $sCountry = "CHRISTMAS ISLAND" Then $sCountryCode = "CX"
  57.     If $sCountry = "COCOS (KEELING) ISLANDS" Then $sCountryCode = "CC"
  58.     If $sCountry = "COLOMBIA" Then $sCountryCode = "CO"
  59.     If $sCountry = "COMOROS" Then $sCountryCode = "KM"
  60.     If $sCountry = "CONGO" Then $sCountryCode = "CG"
  61.     If $sCountry = "CONGO, THE DEMOCRATIC REPUBLIC OF THE" Then $sCountryCode = "CD"
  62.     If $sCountry = "COOK ISLANDS" Then $sCountryCode = "CK"
  63.     If $sCountry = "COSTA RICA" Then $sCountryCode = "CR"
  64.     If $sCountry = "CÔTE D'IVOIRE" Then $sCountryCode = "CI"
  65.     If $sCountry = "CROATIA" Then $sCountryCode = "HR"
  66.     If $sCountry = "CUBA" Then $sCountryCode = "CU"
  67.     If $sCountry = "CURAÇAO" Then $sCountryCode = "CW"
  68.     If $sCountry = "CYPRUS" Then $sCountryCode = "CY"
  69.     If $sCountry = "CZECH REPUBLIC" Then $sCountryCode = "CZ"
  70.     If $sCountry = "DENMARK" Then $sCountryCode = "DK"
  71.     If $sCountry = "DJIBOUTI" Then $sCountryCode = "DJ"
  72.     If $sCountry = "DOMINICA" Then $sCountryCode = "DM"
  73.     If $sCountry = "DOMINICAN REPUBLIC" Then $sCountryCode = "DO"
  74.     If $sCountry = "ECUADOR" Then $sCountryCode = "EC"
  75.     If $sCountry = "EGYPT" Then $sCountryCode = "EG"
  76.     If $sCountry = "EL SALVADOR" Then $sCountryCode = "SV"
  77.     If $sCountry = "EQUATORIAL GUINEA" Then $sCountryCode = "GQ"
  78.     If $sCountry = "ERITREA" Then $sCountryCode = "ER"
  79.     If $sCountry = "ESTONIA" Then $sCountryCode = "EE"
  80.     If $sCountry = "ETHIOPIA" Then $sCountryCode = "ET"
  81.     If $sCountry = "FALKLAND ISLANDS (MALVINAS)" Then $sCountryCode = "FK"
  82.     If $sCountry = "FAROE ISLANDS" Then $sCountryCode = "FO"
  83.     If $sCountry = "FIJI" Then $sCountryCode = "FJ"
  84.     If $sCountry = "FINLAND" Then $sCountryCode = "FI"
  85.     If $sCountry = "FRANCE" Then $sCountryCode = "FR"
  86.     If $sCountry = "FRENCH GUIANA" Then $sCountryCode = "GF"
  87.     If $sCountry = "FRENCH POLYNESIA" Then $sCountryCode = "PF"
  88.     If $sCountry = "FRENCH SOUTHERN TERRITORIES" Then $sCountryCode = "TF"
  89.     If $sCountry = "GABON" Then $sCountryCode = "GA"
  90.     If $sCountry = "GAMBIA" Then $sCountryCode = "GM"
  91.     If $sCountry = "GEORGIA" Then $sCountryCode = "GE"
  92.     If $sCountry = "GERMANY" Then $sCountryCode = "DE"
  93.     If $sCountry = "GHANA" Then $sCountryCode = "GH"
  94.     If $sCountry = "GIBRALTAR" Then $sCountryCode = "GI"
  95.     If $sCountry = "GREECE" Then $sCountryCode = "GR"
  96.     If $sCountry = "GREENLAND" Then $sCountryCode = "GL"
  97.     If $sCountry = "GRENADA" Then $sCountryCode = "GD"
  98.     If $sCountry = "GUADELOUPE" Then $sCountryCode = "GP"
  99.     If $sCountry = "GUAM" Then $sCountryCode = "GU"
  100.     If $sCountry = "GUATEMALA" Then $sCountryCode = "GT"
  101.     If $sCountry = "GUERNSEY" Then $sCountryCode = "GG"
  102.     If $sCountry = "GUINEA" Then $sCountryCode = "GN"
  103.     If $sCountry = "GUINEA-BISSAU" Then $sCountryCode = "GW"
  104.     If $sCountry = "GUYANA" Then $sCountryCode = "GY"
  105.     If $sCountry = "HAITI" Then $sCountryCode = "HT"
  106.     If $sCountry = "HEARD ISLAND AND MCDONALD ISLANDS" Then $sCountryCode = "HM"
  107.     If $sCountry = "HOLY SEE (VATICAN CITY STATE)" Then $sCountryCode = "VA"
  108.     If $sCountry = "HONDURAS" Then $sCountryCode = "HN"
  109.     If $sCountry = "HONG KONG" Then $sCountryCode = "HK"
  110.     If $sCountry = "HUNGARY" Then $sCountryCode = "HU"
  111.     If $sCountry = "ICELAND" Then $sCountryCode = "IS"
  112.     If $sCountry = "INDIA" Then $sCountryCode = "IN"
  113.     If $sCountry = "INDONESIA" Then $sCountryCode = "ID"
  114.     If $sCountry = "IRAN, ISLAMIC REPUBLIC OF" Then $sCountryCode = "IR"
  115.     If $sCountry = "IRAQ" Then $sCountryCode = "IQ"
  116.     If $sCountry = "IRELAND" Then $sCountryCode = "IE"
  117.     If $sCountry = "ISLE OF MAN" Then $sCountryCode = "IM"
  118.     If $sCountry = "ISRAEL" Then $sCountryCode = "IL"
  119.     If $sCountry = "ITALY" Then $sCountryCode = "IT"
  120.     If $sCountry = "JAMAICA" Then $sCountryCode = "JM"
  121.     If $sCountry = "JAPAN" Then $sCountryCode = "JP"
  122.     If $sCountry = "JERSEY" Then $sCountryCode = "JE"
  123.     If $sCountry = "JORDAN" Then $sCountryCode = "JO"
  124.     If $sCountry = "KAZAKHSTAN" Then $sCountryCode = "KZ"
  125.     If $sCountry = "KENYA" Then $sCountryCode = "KE"
  126.     If $sCountry = "KIRIBATI" Then $sCountryCode = "KI"
  127.     If $sCountry = "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF" Then $sCountryCode = "KP"
  128.     If $sCountry = "KOREA, REPUBLIC OF" Then $sCountryCode = "KR"
  129.     If $sCountry = "KUWAIT" Then $sCountryCode = "KW"
  130.     If $sCountry = "KYRGYZSTAN" Then $sCountryCode = "KG"
  131.     If $sCountry = "LAO PEOPLE'S DEMOCRATIC REPUBLIC" Then $sCountryCode = "LA"
  132.     If $sCountry = "LATVIA" Then $sCountryCode = "LV"
  133.     If $sCountry = "LEBANON" Then $sCountryCode = "LB"
  134.     If $sCountry = "LESOTHO" Then $sCountryCode = "LS"
  135.     If $sCountry = "LIBERIA" Then $sCountryCode = "LR"
  136.     If $sCountry = "LIBYA" Then $sCountryCode = "LY"
  137.     If $sCountry = "LIECHTENSTEIN" Then $sCountryCode = "LI"
  138.     If $sCountry = "LITHUANIA" Then $sCountryCode = "LT"
  139.     If $sCountry = "LUXEMBOURG" Then $sCountryCode = "LU"
  140.     If $sCountry = "MACAO" Then $sCountryCode = "MO"
  141.     If $sCountry = "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF" Then $sCountryCode = "MK"
  142.     If $sCountry = "MADAGASCAR" Then $sCountryCode = "MG"
  143.     If $sCountry = "MALAWI" Then $sCountryCode = "MW"
  144.     If $sCountry = "MALAYSIA" Then $sCountryCode = "MY"
  145.     If $sCountry = "MALDIVES" Then $sCountryCode = "MV"
  146.     If $sCountry = "MALI" Then $sCountryCode = "ML"
  147.     If $sCountry = "MALTA" Then $sCountryCode = "MT"
  148.     If $sCountry = "MARSHALL ISLANDS" Then $sCountryCode = "MH"
  149.     If $sCountry = "MARTINIQUE" Then $sCountryCode = "MQ"
  150.     If $sCountry = "MAURITANIA" Then $sCountryCode = "MR"
  151.     If $sCountry = "MAURITIUS" Then $sCountryCode = "MU"
  152.     If $sCountry = "MAYOTTE" Then $sCountryCode = "YT"
  153.     If $sCountry = "MEXICO" Then $sCountryCode = "MX"
  154.     If $sCountry = "MICRONESIA, FEDERATED STATES OF" Then $sCountryCode = "FM"
  155.     If $sCountry = "MOLDOVA, REPUBLIC OF" Then $sCountryCode = "MD"
  156.     If $sCountry = "MONACO" Then $sCountryCode = "MC"
  157.     If $sCountry = "MONGOLIA" Then $sCountryCode = "MN"
  158.     If $sCountry = "MONTENEGRO" Then $sCountryCode = "ME"
  159.     If $sCountry = "MONTSERRAT" Then $sCountryCode = "MS"
  160.     If $sCountry = "MOROCCO" Then $sCountryCode = "MA"
  161.     If $sCountry = "MOZAMBIQUE" Then $sCountryCode = "MZ"
  162.     If $sCountry = "MYANMAR" Then $sCountryCode = "MM"
  163.     If $sCountry = "NAMIBIA" Then $sCountryCode = "NA"
  164.     If $sCountry = "NAURU" Then $sCountryCode = "NR"
  165.     If $sCountry = "NEPAL" Then $sCountryCode = "NP"
  166.     If $sCountry = "NETHERLANDS" Then $sCountryCode = "NL"
  167.     If $sCountry = "NEW CALEDONIA" Then $sCountryCode = "NC"
  168.     If $sCountry = "NEW ZEALAND" Then $sCountryCode = "NZ"
  169.     If $sCountry = "NICARAGUA" Then $sCountryCode = "NI"
  170.     If $sCountry = "NIGER" Then $sCountryCode = "NE"
  171.     If $sCountry = "NIGERIA" Then $sCountryCode = "NG"
  172.     If $sCountry = "NIUE" Then $sCountryCode = "NU"
  173.     If $sCountry = "NORFOLK ISLAND" Then $sCountryCode = "NF"
  174.     If $sCountry = "NORTHERN MARIANA ISLANDS" Then $sCountryCode = "MP"
  175.     If $sCountry = "NORWAY" Then $sCountryCode = "NO"
  176.     If $sCountry = "OMAN" Then $sCountryCode = "OM"
  177.     If $sCountry = "PAKISTAN" Then $sCountryCode = "PK"
  178.     If $sCountry = "PALAU" Then $sCountryCode = "PW"
  179.     If $sCountry = "PALESTINE, STATE OF" Then $sCountryCode = "PS"
  180.     If $sCountry = "PANAMA" Then $sCountryCode = "PA"
  181.     If $sCountry = "PAPUA NEW GUINEA" Then $sCountryCode = "PG"
  182.     If $sCountry = "PARAGUAY" Then $sCountryCode = "PY"
  183.     If $sCountry = "PERU" Then $sCountryCode = "PE"
  184.     If $sCountry = "PHILIPPINES" Then $sCountryCode = "PH"
  185.     If $sCountry = "PITCAIRN" Then $sCountryCode = "PN"
  186.     If $sCountry = "POLAND" Then $sCountryCode = "PL"
  187.     If $sCountry = "PORTUGAL" Then $sCountryCode = "PT"
  188.     If $sCountry = "PUERTO RICO" Then $sCountryCode = "PR"
  189.     If $sCountry = "QATAR" Then $sCountryCode = "QA"
  190.     If $sCountry = "RÉUNION" Then $sCountryCode = "RE"
  191.     If $sCountry = "ROMANIA" Then $sCountryCode = "RO"
  192.     If $sCountry = "RUSSIAN FEDERATION" Then $sCountryCode = "RU"
  193.     If $sCountry = "RWANDA" Then $sCountryCode = "RW"
  194.     If $sCountry = "SAINT BARTHÉLEMY" Then $sCountryCode = "BL"
  195.     If $sCountry = "SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA" Then $sCountryCode = "SH"
  196.     If $sCountry = "SAINT KITTS AND NEVIS" Then $sCountryCode = "KN"
  197.     If $sCountry = "SAINT LUCIA" Then $sCountryCode = "LC"
  198.     If $sCountry = "SAINT MARTIN (FRENCH PART)" Then $sCountryCode = "MF"
  199.     If $sCountry = "SAINT PIERRE AND MIQUELON" Then $sCountryCode = "PM"
  200.     If $sCountry = "SAINT VINCENT AND THE GRENADINES" Then $sCountryCode = "VC"
  201.     If $sCountry = "SAMOA" Then $sCountryCode = "WS"
  202.     If $sCountry = "SAN MARINO" Then $sCountryCode = "SM"
  203.     If $sCountry = "SAO TOME AND PRINCIPE" Then $sCountryCode = "ST"
  204.     If $sCountry = "SAUDI ARABIA" Then $sCountryCode = "SA"
  205.     If $sCountry = "SENEGAL" Then $sCountryCode = "SN"
  206.     If $sCountry = "SERBIA" Then $sCountryCode = "RS"
  207.     If $sCountry = "SEYCHELLES" Then $sCountryCode = "SC"
  208.     If $sCountry = "SIERRA LEONE" Then $sCountryCode = "SL"
  209.     If $sCountry = "SINGAPORE" Then $sCountryCode = "SG"
  210.     If $sCountry = "SINT MAARTEN (DUTCH PART)" Then $sCountryCode = "SX"
  211.     If $sCountry = "SLOVAKIA" Then $sCountryCode = "SK"
  212.     If $sCountry = "SLOVENIA" Then $sCountryCode = "SI"
  213.     If $sCountry = "SOLOMON ISLANDS" Then $sCountryCode = "SB"
  214.     If $sCountry = "SOMALIA" Then $sCountryCode = "SO"
  215.     If $sCountry = "SOUTH AFRICA" Then $sCountryCode = "ZA"
  216.     If $sCountry = "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS" Then $sCountryCode = "GS"
  217.     If $sCountry = "SOUTH SUDAN" Then $sCountryCode = "SS"
  218.     If $sCountry = "SPAIN" Then $sCountryCode = "ES"
  219.     If $sCountry = "SRI LANKA" Then $sCountryCode = "LK"
  220.     If $sCountry = "SUDAN" Then $sCountryCode = "SD"
  221.     If $sCountry = "SURINAME" Then $sCountryCode = "SR"
  222.     If $sCountry = "SVALBARD AND JAN MAYEN" Then $sCountryCode = "SJ"
  223.     If $sCountry = "SWAZILAND" Then $sCountryCode = "SZ"
  224.     If $sCountry = "SWEDEN" Then $sCountryCode = "SE"
  225.     If $sCountry = "SWITZERLAND" Then $sCountryCode = "CH"
  226.     If $sCountry = "SYRIAN ARAB REPUBLIC" Then $sCountryCode = "SY"
  227.     If $sCountry = "TAIWAN, PROVINCE OF CHINA" Then $sCountryCode = "TW"
  228.     If $sCountry = "TAJIKISTAN" Then $sCountryCode = "TJ"
  229.     If $sCountry = "TANZANIA, UNITED REPUBLIC OF" Then $sCountryCode = "TZ"
  230.     If $sCountry = "THAILAND" Then $sCountryCode = "TH"
  231.     If $sCountry = "TIMOR-LESTE" Then $sCountryCode = "TL"
  232.     If $sCountry = "TOGO" Then $sCountryCode = "TG"
  233.     If $sCountry = "TOKELAU" Then $sCountryCode = "TK"
  234.     If $sCountry = "TONGA" Then $sCountryCode = "TO"
  235.     If $sCountry = "TRINIDAD AND TOBAGO" Then $sCountryCode = "TT"
  236.     If $sCountry = "TUNISIA" Then $sCountryCode = "TN"
  237.     If $sCountry = "TURKEY" Then $sCountryCode = "TR"
  238.     If $sCountry = "TURKMENISTAN" Then $sCountryCode = "TM"
  239.     If $sCountry = "TURKS AND CAICOS ISLANDS" Then $sCountryCode = "TC"
  240.     If $sCountry = "TUVALU" Then $sCountryCode = "TV"
  241.     If $sCountry = "UGANDA" Then $sCountryCode = "UG"
  242.     If $sCountry = "UKRAINE" Then $sCountryCode = "UA"
  243.     If $sCountry = "UNITED ARAB EMIRATES" Then $sCountryCode = "AE"
  244.     If $sCountry = "UNITED KINGDOM" Then $sCountryCode = "GB"
  245.     If $sCountry = "UNITED STATES" Then $sCountryCode = "US"
  246.     If $sCountry = "UNITED STATES MINOR OUTLYING ISLANDS" Then $sCountryCode = "UM"
  247.     If $sCountry = "URUGUAY" Then $sCountryCode = "UY"
  248.     If $sCountry = "UZBEKISTAN" Then $sCountryCode = "UZ"
  249.     If $sCountry = "VANUATU" Then $sCountryCode = "VU"
  250.     If $sCountry = "VENEZUELA, BOLIVARIAN REPUBLIC OF" Then $sCountryCode = "VE"
  251.     If $sCountry = "VIET NAM" Then $sCountryCode = "VN"
  252.     If $sCountry = "VIRGIN ISLANDS, BRITISH" Then $sCountryCode = "VG"
  253.     If $sCountry = "VIRGIN ISLANDS, U.S." Then $sCountryCode = "VI"
  254.     If $sCountry = "WALLIS AND FUTUNA" Then $sCountryCode = "WF"
  255.     If $sCountry = "WESTERN SAHARA" Then $sCountryCode = "EH"
  256.     If $sCountry = "YEMEN" Then $sCountryCode = "YE"
  257.     If $sCountry = "ZAMBIA" Then $sCountryCode = "ZM"
  258.     If $sCountry = "ZIMBABWE" Then $sCountryCode = "ZW"
  259.     Return $sCountryCode
  260. EndFunc   ;==>_CountryNameToISO

 

Wouldn't Switch $sCountry work better than all those If statements?


  • DatMCEyeBall likes this

Making dumb decisions and posting without thinking since August 7, 2011. Jury-rigging AutoIt to work how I want successfully since a while.

 

Current Projects:

IRC UDF, for IRC activities

SafeExecute, for picking and choosing what commands you want Execute to be able to run.


#144 gil900

gil900

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 636 posts

Posted 16 March 2014 - 02:02 PM

This code snippet is expansion to _ResourcePlaySound() from Resources UDF.

Thanks to Melba23 for helped me here:

http://www.autoitscript.com/forum/topic/159723-need-help-with-playsound-api/

Without his example, I could not develop this code snippet.

 

 

The purpose of the code is:

To play group of sounds in order without stopping the loop.

 

for example, if you have these sounds: sound1.wav , sound2.wav , sound3.wav

you can play them in order in simple way with my code in this way:

PlaySoundGroup("sound1|sound2|sound3") While 1     $PlaySoundGroup = PlaySoundGroup()     If $PlaySoundGroup = 1 Then         ToolTip("Sounds Playing")     ElseIf $PlaySoundGroup = 0 Then         MsgBox(0,"","Sounds Stopped")         Exit     EndIf     Sleep(50) WEnd

Full examle attached to this post.

 

EDIT:

I updated the code and example.

Attached Files


Edited by gil900, 16 March 2014 - 03:29 PM.

Please correct my English in this post. I want to learn how to write correctly in English


#145 j981

j981

    Seeker

  • Normal Members
  • 2 posts

Posted 17 March 2014 - 10:18 AM

I had a need to change the z-order of windows and their position in the "alt-tab" list. I spent quite a long time trying to figure out how to make it happen, so I thought I'd post this snippet back since I finally came up with a workable solution.

 

USE CASE: I bring music applications to the foreground while I'm working/etc via a hotkey. I then press the hotkey again in order to minimize the program. When I did that, however, my alt-tab order was then modified so that I couldn't continue to "alt-tab" between active windows I was working on, which is a distraction that hurt my workflow. I wanted a way to set a window to the back of the alt-tab list and also to change the z-order of a window (two different problems, as it turned out). I've used this with Windows 8.1.

 

I'm not sure if "WinWaitDelay" is applicable to WinSetState operations. I just have it there for good measure. The _WinAPI_FlashWindowEx bit is needed sometimes to prevent windows from automatically flashing the newly un-hidden window. Also, two ancillary functions are used in order to ensure that a different window is active than the one that is to be sent to the back, since this doesn't seem to work right unless that is the case.

AutoIt         
#include <WinAPI.au3> $handle = WinGetHandle("A window which you would like to send to the back of all other windows") _SendToBottom($handle) Func _LastWindowTitle($z = 1)     If $z < 1 Then Return SetError(1, 0, 0) ; Bad parameter     Local $avList = WinList()     For $n = 1 to $avList[0][0]         If $avList[$n][0] <> "" And BitAND(WinGetState($avList[$n][1]), 2) Then             If $z Then                 $z -= 1             Else                 Local $arr = [$avList[$n][0],$avList[$n][1]]                 Return $arr             EndIf         EndIf     Next     Return SetError(2, 0, 0) ; z-depth exceeded EndFunc Func _FastActivate($hWnd)     Opt("WinWaitDelay", 20)     WinActivate($hWnd)     WinWaitActive($hWnd,"",4)     _WinAPI_FlashWindowEx($hWnd,0,0,0)     Opt("WinWaitDelay", 250) EndFunc Func _SendToBottom($hWnd)     Local Const $HWND_BOTTOM = 1;     Opt("WinWaitDelay", 20)     Local $active = WinGetHandle("[ACTIVE]")     Local $lastWindow = _LastWindowTitle()     Local $lastHandle = $lastWindow[1]     If Not ($hWnd <> $active) Then         If (WinExists($lastHandle)) Then             _FastActivate($lastHandle)         EndIf     EndIf     DllCall("user32.dll", "long", "SetWindowPos", "uint", $hWnd, "uint", $HWND_BOTTOM , "int", 0, "int", 0, "int", 0, "int", 0 , "uint", 0x13)     WinSetState($hWnd,"",@SW_MINIMIZE)     WinSetState($hWnd,"",@SW_HIDE)     WinSetState($hWnd,"",@SW_SHOW)     ;disable the taskbar flashing that sometimes occurs when hiding and showing windows...     _WinAPI_FlashWindowEx($hWnd,0,0,0)     Opt("WinWaitDelay", 250) EndFunc

Edited by j981, 22 March 2014 - 03:37 PM.


#146 j981

j981

    Seeker

  • Normal Members
  • 2 posts

Posted 17 March 2014 - 10:26 AM

This is another simple function I've found to be quite handy.

 

USE CASE: Since chrome v32 and later no longer exposes any standard windows API controls, a huge number of "controlsend" based automation functions I was using against webapps broke. I changed things to bring those windows to the foreground instead to send keys and then minimize them again (with the _SendToBottom function I just posted as well), but with the standard 'winactivate' it took too long. This function basically just reduces the winwaitdelay temporarily, but it also disables the automatic flashing of windows in the taskbar which occurs if you activate windows too rapidly, which was extremely annoying. It's not particularly useful if you just want to bring something to the foreground to actively work with, but if the goal is to activate something solely to send a key and then minimize again, it speeds things up quite a bit since it happens almost instantly. Hopefully someone else also finds this useful.

#include <WinAPI.au3> $handle = WinGetHandle("Some window you would like to activate") _FastActivate($handle) Func _FastActivate($hWnd)     Opt("WinWaitDelay", 20)     WinActivate($hWnd)     WinWaitActive($hWnd,"",4)     _WinAPI_FlashWindowEx($hWnd,0,0,0)     Opt("WinWaitDelay", 250) EndFunc

Edited by j981, 17 March 2014 - 10:40 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users