List of Countries

In replying to another topic by @MarkusWinter, I needed a list of all countries to replicate some behaviour seen in the ComboBox. For future use, here’s a method that will return a String array containing all countries. It might be useful for others.

Protected Function ListOfAllCountries() as String()
  Return Array("United States of America", "Afghanistan", "Albania", "Algeria", _
  "Andorra", "Angola", "Antigua & Deps", "Argentina", "Armenia", "Australia", _
  "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", _
  "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia Herzegovina", _
  "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina", "Burma", "Burundi", "Cambodia", _
  "Cameroon", "Canada", "Cape Verde", "Central African Rep", "Chad", "Chile", _
  "People's Republic of China", "Colombia", "Comoros", _
  "Democratic Republic of the Congo", "Republic of the Congo", "Costa Rica,", _
  "Croatia", "Cuba", "Cyprus", "Czech Republic", "Danzig", "Denmark", "Djibouti", _
  "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", _
  "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France", _
  "Gabon", "The Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", _
  "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", _
  "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Republic of Ireland", _
  "Israel", "Italy", "Ivory Coast", "Jamaica", "Japan", "Jonathanland", "Jordan", _
  "Kazakhstan", "Kenya", "Kiribati", "North Korea", "South Korea", "Kosovo", "Kuwait", _
  "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", _
  "Lithuania", "Luxembourg", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", _
  "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", _
  "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", _
  "Mount Athos", "Mozambique", "Namibia", "Nauru", "Nepal", "Newfoundland", _
  "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", _
  "Ottoman Empire", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", _
  "Peru", "Philippines", "Poland", "Portugal", "Prussia", "Qatar", "Romania", "Rome", _
  "Russian Federation", "Rwanda", "St Kitts & Nevis", "St Lucia", "Saint Vincent & the", _
  "Grenadines", "Samoa", "San Marino", "Sao Tome & Principe", "Saudi Arabia", "Senegal", _
  "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", _
  "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", _
  "Swaziland", "Sweden", "Switzerland", "Syria", "Tajikistan", "Tanzania", "Thailand", _
  "Togo", "Tonga", "Trinidad & Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", _
  "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "Uruguay", _
  "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Yemen", _
  "Zambia", "Zimbabwe")
End Function

1 Like

nice!

I think where I would do something different would be to take advantage of a sqlite database to store large list in a table. In the function, I would call to query the list and present to the front end.

I thought of an SQLite database but thought a list array is simpler since the data almost never changes. Here is my attempt which allows the International phone code to be at the front (for phone numbers) and the option of placing your countries of choice at the front:

getCountries(includephoneCode As Boolean = False, myBrackets As String = "", westernAtFront As Boolean = True) As String()

Dim allPhoneCodes(-1) As String
Dim myPhoneCodes(-1) As String
Dim tempString As String

If westernAtFront Then
  allPhoneCodes.Append("61«T»Australia")
  allPhoneCodes.Append("1«T»Canada")
  allPhoneCodes.Append("64«T»New Zealand")
  allPhoneCodes.Append("44«T»United Kingdom")
  allPhoneCodes.Append("1«T»United States of America")
  allPhoneCodes.Append("-")
End If

allPhoneCodes.Append("99544«T»Abkhazia")
allPhoneCodes.Append("93«T»Afghanistan")
allPhoneCodes.Append("355«T»Albania")
allPhoneCodes.Append("213«T»Algeria")
allPhoneCodes.Append("1684«T»American Samoa")
allPhoneCodes.Append("376«T»Andorra")
allPhoneCodes.Append("244«T»Angola")
allPhoneCodes.Append("1264«T»Anguilla")
allPhoneCodes.Append("672«T»Antarctica")
allPhoneCodes.Append("1268«T»Antigua and Barbuda")
allPhoneCodes.Append("54«T»Argentina")
allPhoneCodes.Append("374«T»Armenia")
allPhoneCodes.Append("297«T»Aruba")
allPhoneCodes.Append("247«T»Ascension Island")
If Not westernAtFront Then allPhoneCodes.Append("61«T»Australia")
allPhoneCodes.Append("43«T»Austria")
allPhoneCodes.Append("994«T»Azerbaijan")
allPhoneCodes.Append("1242«T»Bahamas")
allPhoneCodes.Append("973«T»Bahrain")
allPhoneCodes.Append("880«T»Bangladesh")
allPhoneCodes.Append("1246«T»Barbados")
allPhoneCodes.Append("375«T»Belarus")
allPhoneCodes.Append("32«T»Belgium")
allPhoneCodes.Append("501«T»Belize")
allPhoneCodes.Append("229«T»Benin")
allPhoneCodes.Append("1441«T»Bermuda")
allPhoneCodes.Append("975«T»Bhutan")
allPhoneCodes.Append("591«T»Bolivia")
allPhoneCodes.Append("5997«T»Bonaire")
allPhoneCodes.Append("387«T»Bosnia and Herzegovina")
allPhoneCodes.Append("267«T»Botswana")
allPhoneCodes.Append("47«T»Bouvet Island")
allPhoneCodes.Append("55«T»Brazil")
allPhoneCodes.Append("246«T»British Indian Ocean Territory")
allPhoneCodes.Append("1284«T»British Virgin Islands")
allPhoneCodes.Append("673«T»Brunei")
allPhoneCodes.Append("359«T»Bulgaria")
allPhoneCodes.Append("226«T»Burkina Faso")
allPhoneCodes.Append("95«T»Burma")
allPhoneCodes.Append("257«T»Burundi")
allPhoneCodes.Append("855«T»Cambodia")
allPhoneCodes.Append("237«T»Cameroon")
If Not westernAtFront Then allPhoneCodes.Append("1«T»Canada")
allPhoneCodes.Append("238«T»Cape Verde")
allPhoneCodes.Append("1345«T»Cayman Islands")
allPhoneCodes.Append("236«T»Central African Republic")
allPhoneCodes.Append("235«T»Chad")
allPhoneCodes.Append("56«T»Chile")
allPhoneCodes.Append("86«T»China«T»Mainland)")
allPhoneCodes.Append("6189164«T»Christmas Island")
allPhoneCodes.Append("6189162«T»Cocos Islands")
allPhoneCodes.Append("57«T»Colombia")
allPhoneCodes.Append("269«T»Comoros")
allPhoneCodes.Append("682«T»Cook Islands")
allPhoneCodes.Append("506«T»Costa Rica")
allPhoneCodes.Append("225«T»Côte d'Ivoire")
allPhoneCodes.Append("385«T»Croatia")
allPhoneCodes.Append("53«T»Cuba")
allPhoneCodes.Append("5999«T»Curacao")
allPhoneCodes.Append("357«T»Cyprus")
allPhoneCodes.Append("420«T»Czech Republic")
allPhoneCodes.Append("243«T»Democratic Republic of the Congo")
allPhoneCodes.Append("45«T»Denmark")
allPhoneCodes.Append("253«T»Djibouti")
allPhoneCodes.Append("1767«T»Dominica")
allPhoneCodes.Append("1809«T»Dominican Republic")
allPhoneCodes.Append("1829«T»Dominican Republic")
allPhoneCodes.Append("1849«T»Dominican Republic")
allPhoneCodes.Append("670«T»East Timor")
allPhoneCodes.Append("593«T»Ecuador")
allPhoneCodes.Append("20«T»Egypt")
allPhoneCodes.Append("503«T»El Salvador")
allPhoneCodes.Append("44«T»England")
allPhoneCodes.Append("240«T»Equatorial Guinea")
allPhoneCodes.Append("291«T»Eritrea")
allPhoneCodes.Append("372«T»Estonia")
allPhoneCodes.Append("251«T»Ethiopia")
allPhoneCodes.Append("500«T»Falkland Islands")
allPhoneCodes.Append("298«T»Faroe Islands")
allPhoneCodes.Append("691«T»Federated States of Micronesia")
allPhoneCodes.Append("679«T»Fiji")
allPhoneCodes.Append("358«T»Finland")
allPhoneCodes.Append("33«T»France")
allPhoneCodes.Append("594«T»French Guiana")
allPhoneCodes.Append("689«T»French Polynesia")
allPhoneCodes.Append("262«T»French Southern Territories")
allPhoneCodes.Append("241«T»Gabon")
allPhoneCodes.Append("220«T»Gambia")
allPhoneCodes.Append("995«T»Georgia")
allPhoneCodes.Append("49«T»Germany")
allPhoneCodes.Append("233«T»Ghana")
allPhoneCodes.Append("350«T»Gibraltar")
allPhoneCodes.Append("30«T»Greece")
allPhoneCodes.Append("299«T»Greenland")
allPhoneCodes.Append("1473«T»Grenada")
allPhoneCodes.Append("590«T»Guadeloupe)")
allPhoneCodes.Append("1671«T»Guam")
allPhoneCodes.Append("502«T»Guatemala")
allPhoneCodes.Append("441481«T»Guernsey")
allPhoneCodes.Append("224«T»Guinea")
allPhoneCodes.Append("245«T»Guinea-Bissau")
allPhoneCodes.Append("592«T»Guyana")
allPhoneCodes.Append("509«T»Haiti")
allPhoneCodes.Append("672«T»Heard and McDonald Islands")
allPhoneCodes.Append("504«T»Honduras")
allPhoneCodes.Append("852«T»Hong Kong")
allPhoneCodes.Append("36«T»Hungary")
allPhoneCodes.Append("354«T»Iceland")
allPhoneCodes.Append("91«T»India")
allPhoneCodes.Append("62«T»Indonesia")
allPhoneCodes.Append("98«T»Iran")
allPhoneCodes.Append("964«T»Iraq")
allPhoneCodes.Append("353«T»Ireland")
allPhoneCodes.Append("441624«T»Isle of Man")
allPhoneCodes.Append("972«T»Israel")
allPhoneCodes.Append("39«T»Italy")
allPhoneCodes.Append("1876«T»Jamaica")
allPhoneCodes.Append("81«T»Japan")
allPhoneCodes.Append("441534«T»Jersey")
allPhoneCodes.Append("962«T»Jordan")
allPhoneCodes.Append("7«T»Kazakhstan")
allPhoneCodes.Append("254«T»Kenya")
allPhoneCodes.Append("686«T»Kiribati")
allPhoneCodes.Append("965«T»Kuwait")
allPhoneCodes.Append("996«T»Kyrgyzstan")
allPhoneCodes.Append("856«T»Laos")
allPhoneCodes.Append("371«T»Latvia")
allPhoneCodes.Append("961«T»Lebanon")
allPhoneCodes.Append("266«T»Lesotho")
allPhoneCodes.Append("231«T»Liberia")
allPhoneCodes.Append("218«T»Libya")
allPhoneCodes.Append("423«T»Liechtenstein")
allPhoneCodes.Append("370«T»Lithuania")
allPhoneCodes.Append("352«T»Luxembourg")
allPhoneCodes.Append("853«T»Macau")
allPhoneCodes.Append("389«T»Macedonia")
allPhoneCodes.Append("261«T»Madagascar")
allPhoneCodes.Append("265«T»Malawi")
allPhoneCodes.Append("60«T»Malaysia")
allPhoneCodes.Append("960«T»Maldives")
allPhoneCodes.Append("223«T»Mali")
allPhoneCodes.Append("356«T»Malta")
allPhoneCodes.Append("692«T»Marshall Islands")
allPhoneCodes.Append("596«T»Martinique")
allPhoneCodes.Append("222«T»Mauritania")
allPhoneCodes.Append("230«T»Mauritius")
allPhoneCodes.Append("262«T»Mayotte")
allPhoneCodes.Append("52«T»Mexico")
allPhoneCodes.Append("373«T»Moldova")
allPhoneCodes.Append("377«T»Monaco")
allPhoneCodes.Append("976«T»Mongolia")
allPhoneCodes.Append("382«T»Montenegro")
allPhoneCodes.Append("1664«T»Montserrat")
allPhoneCodes.Append("212«T»Morocco")
allPhoneCodes.Append("258«T»Mozambique")
allPhoneCodes.Append("264«T»Namibia")
allPhoneCodes.Append("674«T»Nauru")
allPhoneCodes.Append("977«T»Nepal")
allPhoneCodes.Append("31«T»Netherlands")
allPhoneCodes.Append("599«T»Netherlands Antilles")
allPhoneCodes.Append("687«T»New Caledonia")
If Not westernAtFront Then allPhoneCodes.Append("64«T»New Zealand")
allPhoneCodes.Append("505«T»Nicaragua")
allPhoneCodes.Append("227«T»Niger")
allPhoneCodes.Append("234«T»Nigeria")
allPhoneCodes.Append("683«T»Niue")
allPhoneCodes.Append("6723«T»Norfolk Island")
allPhoneCodes.Append("850«T»North Korea")
allPhoneCodes.Append("90392«T»Northern Cyprus")
allPhoneCodes.Append("44«T»Northern Ireland")
allPhoneCodes.Append("1670«T»Northern Mariana Islands")
allPhoneCodes.Append("47«T»Norway")
allPhoneCodes.Append("968«T»Oman")
allPhoneCodes.Append("92«T»Pakistan")
allPhoneCodes.Append("680«T»Palau")
allPhoneCodes.Append("970«T»Palestinian territories")
allPhoneCodes.Append("507«T»Panama")
allPhoneCodes.Append("675«T»Papua New Guinea")
allPhoneCodes.Append("595«T»Paraguay")
allPhoneCodes.Append("51«T»Peru")
allPhoneCodes.Append("63«T»Philippines")
allPhoneCodes.Append("64«T»Pitcairn Island")
allPhoneCodes.Append("48«T»Poland")
allPhoneCodes.Append("351«T»Portugal")
allPhoneCodes.Append("1787«T»Puerto Rico")
allPhoneCodes.Append("1939«T»Puerto Rico")
allPhoneCodes.Append("974«T»Qatar")
allPhoneCodes.Append("242«T»Republic of the Congo")
allPhoneCodes.Append("262«T»Réunion")
allPhoneCodes.Append("40«T»Romania")
allPhoneCodes.Append("7«T»Russia")
allPhoneCodes.Append("250«T»Rwanda")
allPhoneCodes.Append("5994«T»Saba")
allPhoneCodes.Append("590«T»Saint Barthélemy")
allPhoneCodes.Append("5993«T»Saint Eustatius")
allPhoneCodes.Append("290«T»Saint Helena")
allPhoneCodes.Append("1869«T»Saint Kitts and Nevis")
allPhoneCodes.Append("1758«T»Saint Lucia")
allPhoneCodes.Append("590«T»Saint Martin")
allPhoneCodes.Append("1784«T»Saint Vincent and the Grenadines")
allPhoneCodes.Append("508«T»Saint-Pierre and Miquelon")
allPhoneCodes.Append("685«T»Samoa")
allPhoneCodes.Append("378«T»San Marino")
allPhoneCodes.Append("239«T»São Tomé and Príncipe")
allPhoneCodes.Append("966«T»Saudi Arabia")
allPhoneCodes.Append("44«T»Scotland")
allPhoneCodes.Append("221«T»Senegal")
allPhoneCodes.Append("381«T»Serbia")
allPhoneCodes.Append("248«T»Seychelles")
allPhoneCodes.Append("232«T»Sierra Leone")
allPhoneCodes.Append("65«T»Singapore")
allPhoneCodes.Append("5995«T»Sint Maarten")
allPhoneCodes.Append("421«T»Slovakia")
allPhoneCodes.Append("386«T»Slovenia")
allPhoneCodes.Append("677«T»Solomon Islands")
allPhoneCodes.Append("252«T»Somalia")
allPhoneCodes.Append("27«T»South Africa")
allPhoneCodes.Append("82«T»South Korea")
allPhoneCodes.Append("34«T»Spain")
allPhoneCodes.Append("94«T»Sri Lanka")
allPhoneCodes.Append("249«T»Sudan")
allPhoneCodes.Append("597«T»Suriname")
allPhoneCodes.Append("47«T»Svalbard and Jan Mayen Islands")
allPhoneCodes.Append("268«T»Swaziland")
allPhoneCodes.Append("46«T»Sweden")
allPhoneCodes.Append("41«T»Switzerland")
allPhoneCodes.Append("963«T»Syria")
allPhoneCodes.Append("886«T»Taiwan")
allPhoneCodes.Append("992«T»Tajikistan")
allPhoneCodes.Append("255«T»Tanzania")
allPhoneCodes.Append("66«T»Thailand")
allPhoneCodes.Append("228«T»Togo")
allPhoneCodes.Append("690«T»Tokelau")
allPhoneCodes.Append("676«T»Tonga")
allPhoneCodes.Append("1868«T»Trinidad and Tobago")
allPhoneCodes.Append("216«T»Tunisia")
allPhoneCodes.Append("90«T»Turkey")
allPhoneCodes.Append("993«T»Turkmenistan")
allPhoneCodes.Append("1649«T»Turks and Caicos Islands")
allPhoneCodes.Append("688«T»Tuvalu")
allPhoneCodes.Append("1340«T»U.S. Virgin Islands")
allPhoneCodes.Append("256«T»Uganda")
allPhoneCodes.Append("380«T»Ukraine")
allPhoneCodes.Append("971«T»United Arab Emirates")
If Not westernAtFront Then allPhoneCodes.Append("44«T»United Kingdom")
If Not westernAtFront Then allPhoneCodes.Append("1«T»United States of America")
allPhoneCodes.Append("598«T»Uruguay")
allPhoneCodes.Append("699«T»U.S. Minor Outlying Islands")
allPhoneCodes.Append("998«T»Uzbekistan")
allPhoneCodes.Append("678«T»Vanuatu")
allPhoneCodes.Append("379«T»Vatican City")
allPhoneCodes.Append("58«T»Venezuela")
allPhoneCodes.Append("84«T»Vietnam")
allPhoneCodes.Append("44«T»Wales")
allPhoneCodes.Append("681«T»Wallis and Futuna Islands")
allPhoneCodes.Append("289«T»Western Sahara")
allPhoneCodes.Append("212288«T»Western Sahara")
allPhoneCodes.Append("967«T»Yemen")
allPhoneCodes.Append("260«T»Zambia")
allPhoneCodes.Append("263«T»Zimbabwe")

For tempInt As Integer = 0 To allPhoneCodes.Ubound
  tempString = ""
  If includephoneCode Then
    tempString = NthField(allPhoneCodes(tempInt), "«T»", 1)
  End If
  If tempString <> "-" Then
    tempString = tempString + If(myBrackets <> "", " " + Left(myBrackets, 1), "") + NthField(allPhoneCodes(tempInt), "«T»", 2) + If(myBrackets <> "", Right(myBrackets, 1), "")
  End If
  myPhoneCodes.Append(tempString)
Next

Return myPhoneCodes
1 Like

Where did you get that list? There are very odd entries:

Gaza isn’t a country
2x times China
Holy Roman Empire???
Taiwan is missing

I can’t remember the exact source - I think it might have been StackOverflow.

I’ve removed the duplicate China entry and the bizarre Holy Roman Empire entry (that’s not been a nation since 1806! I’ve removed Gaza.

Taiwan isn’t recognised as an independent nation by the UK. It’s part of the People’s Republic of China according to the UK government: Source.

Maybe use this list:

Protected Function CreateListOfAllCountries() as String()
  Return Array("Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", _
  "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", _
  "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", _
  "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", _
  "Cameroon", "Canada", "Central African Republic (CAR)", "Chad", "Chile", "China", "Colombia", "Comoros", _
  "Congo, Democratic Republic of the", "Congo, Republic of the", "Costa Rica", "Cote d'Ivoire", "Croatia", _
  "Cuba", "Cyprus", "Czechia", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", _
  "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini (formerly Swaziland)", "Ethiopia", _
  "Fiji", "Finland", "France", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", _
  "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", _
  "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", _
  "Kenya", "Kiribati", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", _
  "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Madagascar", "Malawi", "Malaysia", "Maldives", _
  "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", _
  "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar (formerly Burma)", "Namibia", _
  "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "North Korea", _
  "North Macedonia (formerly Macedonia)", "Norway", "Oman", "Pakistan", "Palau", "Palestine", "Panama", _
  "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", _
  "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", _
  "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", _
  "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Korea", _
  "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Sweden", "Switzerland", "Syria", "Taiwan", _
  "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", _
  "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates (UAE)", "United Kingdom (UK)", _
  "United States of America (USA)", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City (Holy See)", _
  "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe")
  
End Function