Class For All Countries with their flags-VBForums
Results 1 to 11 of 11

Thread: Class For All Countries with their flags

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,817

    Class For All Countries with their flags

    I saw a post today that asked how to link a country's name to it's flag. I suggested that they use a dictionary or a database, then I realized how long it would take to download all the flags and then load them into that database. Well I went ahead and did it. It takes a while for the items to be added to the dictionary, it should probolly be done in a seperate thread, but I'm just to lazy to do it.

    Here is zip with all the flags the file is 4.69MB which is to large for VBForums to allow me to post it, so I posted it to SkyDrive:
    Flags
    Btw, if for what ever reason the flag link is broken, please either PM or post here.

    Here is the class:
    Code:
    Option Strict On
    Option Explicit On
    Public Class Countries
        Inherits Dictionary(Of String, Image)
    
        Public Sub New()
    
    
            Me.Add("Afghanistan", My.Resources.Afghanistan)
            Me.Add("Albania", My.Resources.Albania)
            Me.Add("Algeria", My.Resources.Algeria)
            Me.Add("American Samoa", My.Resources.American_Samoa)
            Me.Add("Andorra", My.Resources.Andorra)
            Me.Add("Angola", My.Resources.Angola)
            Me.Add("Anguilla", My.Resources.Anguilla)
            Me.Add("Antigua and Barbuda", My.Resources.Antigua_and_Barbuda)
            Me.Add("Argentina", My.Resources.Argentina)
            Me.Add("Armenia", My.Resources.Armenia)
            Me.Add("Aruba", My.Resources.Aruba)
            Me.Add("Australia", My.Resources.Australia)
            Me.Add("Austria", My.Resources.Austria)
            Me.Add("Azerbaijan", My.Resources.Azerbaijan)
            Me.Add("Bahamas", My.Resources.Bahamas)
            Me.Add("Bahrain", My.Resources.Bahrain)
            Me.Add("Bangladesh", My.Resources.Bangladesh)
            Me.Add("Barbados", My.Resources.Barbados)
            Me.Add("Belarus", My.Resources.Belarus)
            Me.Add("Belgium", My.Resources.Belgium)
            Me.Add("Belize", My.Resources.Belize)
            Me.Add("Benin", My.Resources.Benin)
            Me.Add("Bermuda", My.Resources.Bermuda)
            Me.Add("Bhutan", My.Resources.Bhutan)
            Me.Add("Bolivia", My.Resources.Bolivia)
            Me.Add("Bosnia", My.Resources.Bosnia)
            Me.Add("Botswana", My.Resources.Botswana)
            Me.Add("Brazil", My.Resources.Brazil)
            Me.Add("British Virgin Islands", My.Resources.British_Virgin_Islands)
            Me.Add("Brunei", My.Resources.Brunei)
            Me.Add("Bulgaria", My.Resources.Bulgaria)
            Me.Add("Burkina Faso", My.Resources.Burkina_Faso)
            Me.Add("Burundi", My.Resources.Burundi)
            Me.Add("Cambodia", My.Resources.Cambodia)
            Me.Add("Cameroon", My.Resources.Cameroon)
            Me.Add("Canada", My.Resources.Canada)
            Me.Add("Cape Verde", My.Resources.Cape_Verde)
            Me.Add("Cayman Islands", My.Resources.Cayman_Islands)
            Me.Add("Central African Republic", My.Resources.Central_African_Republic)
            Me.Add("Chad", My.Resources.Chad)
            Me.Add("Chile", My.Resources.Chile)
            Me.Add("China", My.Resources.China)
            Me.Add("Christmas Islands", My.Resources.Christmas_Island)
            Me.Add("Colombia", My.Resources.Colombia)
            Me.Add("Comoros", My.Resources.Comoros)
            Me.Add("Cook Islands", My.Resources.Cook_Islands)
            Me.Add("Costa Rica", My.Resources.Costa_Rica)
            Me.Add("Croatia", My.Resources.Croatia)
            Me.Add("Cuba", My.Resources.Cuba)
            Me.Add("Cyprus", My.Resources.Cyprus)
            Me.Add("Czech Republic", My.Resources.Czech_Republic)
            Me.Add("Democratic Republic of the Congo", My.Resources.Democratic_Republic_of_the_Congo)
            Me.Add("East Timor", My.Resources.East_Timor)
            Me.Add("Ecuador", My.Resources.Ecuador)
            Me.Add("Egypt", My.Resources.Egypt)
            Me.Add("El Salvador", My.Resources.El_Salvador)
            Me.Add("Equatorial Guinea", My.Resources.Equatorial_Guinea)
            Me.Add("Eritrea", My.Resources.Eritrea)
            Me.Add("Estonia", My.Resources.Estonia)
            Me.Add("Ethiopia", My.Resources.Ethiopia)
            Me.Add("Falkland Islands", My.Resources.Falkland_Islands)
            Me.Add("Faroe Islands", My.Resources.Faroe_Islands)
            Me.Add("Fiji", My.Resources.Fiji)
            Me.Add("Finland", My.Resources.Finland)
            Me.Add("France", My.Resources.France)
            Me.Add("French Polynesia", My.Resources.French_Polynesia)
            Me.Add("Gabon", My.Resources.Gabon)
            Me.Add("Gambia", My.Resources.Gambia)
            Me.Add("Georgia", My.Resources.Georgia)
            Me.Add("Germany", My.Resources.Germany)
            Me.Add("Ghana", My.Resources.Ghana)
            Me.Add("Gibraltar", My.Resources.Gibraltar)
            Me.Add("Greece", My.Resources.Greece)
            Me.Add("Greenland", My.Resources.Greenland)
            Me.Add("Grenada", My.Resources.Grenada)
            Me.Add("Guam", My.Resources.Guam)
            Me.Add("Guatemala", My.Resources.Guatemala)
            Me.Add("Guinea", My.Resources.Guinea)
            Me.Add("Guinea Bissau", My.Resources.Guinea_Bissau)
            Me.Add("Guyana", My.Resources.Guyana)
            Me.Add("Haiti", My.Resources.Haiti)
            Me.Add("Honduras", My.Resources.Honduras)
            Me.Add("Hong Kong", My.Resources.Hong_Kong)
            Me.Add("Hungary", My.Resources.Hungary)
            Me.Add("Iceland", My.Resources.Iceland)
            Me.Add("India", My.Resources.India)
            Me.Add("Indonesia", My.Resources.Indonesia)
            Me.Add("Iran", My.Resources.Iran)
            Me.Add("Iraq", My.Resources.Iraq)
            Me.Add("Ireland", My.Resources.Ireland)
            Me.Add("Israel", My.Resources.Israel)
            Me.Add("Italy", My.Resources.Italy)
            Me.Add("Ivory Coast", My.Resources.Ivory_Coast)
            Me.Add("Jamaica", My.Resources.Jamaica)
            Me.Add("Japan", My.Resources.Japan)
            Me.Add("Jordan", My.Resources.Jordan)
            Me.Add("Kazakhstan", My.Resources.Kazakhstan)
            Me.Add("Kenya", My.Resources.Kenya)
            Me.Add("Kiribati", My.Resources.Kiribati)
            Me.Add("Kuwait", My.Resources.Kuwait)
            Me.Add("Kyrgyzstan", My.Resources.Kyrgyzstan)
            Me.Add("Laos", My.Resources.Laos)
            Me.Add("Latvia", My.Resources.Latvia)
            Me.Add("Lebanon", My.Resources.Lebanon)
            Me.Add("Lesotho", My.Resources.Lesotho)
            Me.Add("Liberia", My.Resources.Liberia)
            Me.Add("Libya", My.Resources.Libya)
            Me.Add("Liechtenstein", My.Resources.Liechtenstein)
            Me.Add("Lithuania", My.Resources.Lithuania)
            Me.Add("Luxembourg", My.Resources.Luxembourg)
            Me.Add("Macao", My.Resources.Macao)
            Me.Add("Macedonia", My.Resources.Macedonia)
            Me.Add("Madagascar", My.Resources.Madagascar)
            Me.Add("Malawi", My.Resources.Malawi)
            Me.Add("Malaysia", My.Resources.Malaysia)
            Me.Add("Maldives", My.Resources.Maldives)
            Me.Add("Mali", My.Resources.Mali)
            Me.Add("Malta", My.Resources.Malta)
            Me.Add("Marshall Islands", My.Resources.Marshall_Islands)
            Me.Add("Martinique", My.Resources.Martinique)
            Me.Add("Mauritania", My.Resources.Mauritania)
            Me.Add("Mexico", My.Resources.Mexico)
            Me.Add("Micronesia", My.Resources.Micronesia)
            Me.Add("Moldova", My.Resources.Moldova)
            Me.Add("Monaco", My.Resources.Monaco)
            Me.Add("Mongolia", My.Resources.Mongolia)
            Me.Add("Montserrat", My.Resources.Montserrat)
            Me.Add("Morocoo", My.Resources.Morocco)
            Me.Add("Mozambique", My.Resources.Mozambique)
            Me.Add("Myanmar", My.Resources.Myanmar)
            Me.Add("Namibia", My.Resources.Namibia)
            Me.Add("Nauru", My.Resources.Nauru)
            Me.Add("Nepal", My.Resources.Nepal)
            Me.Add("Netherlands", My.Resources.Netherlands)
            Me.Add("Netherlands Antilles", My.Resources.Netherlands_Antilles)
            Me.Add("New Zealand", My.Resources.New_Zealand)
            Me.Add("Nicaragua", My.Resources.Nicaragua)
            Me.Add("Niger", My.Resources.Niger)
            Me.Add("Nigeria", My.Resources.Nigeria)
            Me.Add("Niue", My.Resources.Niue)
            Me.Add("Norfolk Island", My.Resources.Norfolk_Island)
            Me.Add("North Korea", My.Resources.North_Korea)
            Me.Add("Norway", My.Resources.Norway)
            Me.Add("Oman", My.Resources.Oman)
            Me.Add("Pakistan", My.Resources.Pakistan)
            Me.Add("Palau", My.Resources.Palau)
            Me.Add("Panama", My.Resources.Panama)
            Me.Add("Papua New Guinea", My.Resources.Papua_New_Guinea)
            Me.Add("Paraguay", My.Resources.Paraguay)
            Me.Add("Peru", My.Resources.Peru)
            Me.Add("Philippines", My.Resources.Philippines)
            Me.Add("Pitcairn Islands", My.Resources.Pitcairn_Islands)
            Me.Add("Poland", My.Resources.Poland)
            Me.Add("Portugal", My.Resources.Portugal)
            Me.Add("Puerto Rico", My.Resources.Puerto_Rico)
            Me.Add("Qatar", My.Resources.Qatar)
            Me.Add("Republic of the Congo", My.Resources.Republic_of_the_Congo)
            Me.Add("Romania", My.Resources.Romania)
            Me.Add("Russian Federation", My.Resources.Russian_Federation)
            Me.Add("Rwanda", My.Resources.Rwanda)
            Me.Add("Saint Kitts and Nevis", My.Resources.Saint_Kitts_and_Nevis)
            Me.Add("Saint Lucia", My.Resources.Saint_Lucia)
            Me.Add("Saint Pierre", My.Resources.Saint_Pierre)
            Me.Add("Saint Vicent and the Grenadines", My.Resources.Saint_Vicent_and_the_Grenadines)
            Me.Add("Samoa", My.Resources.Samoa)
            Me.Add("Sao Tome and Principe", My.Resources.Sao_Tomé_and_Príncipe)
            Me.Add("Saudi Arabia", My.Resources.Saudi_Arabia)
            Me.Add("Senegal", My.Resources.Senegal)
            Me.Add("Serbia and Montenegro", My.Resources.Serbia_and_Montenegro)
            Me.Add("Seychelles", My.Resources.Seychelles)
            Me.Add("Sierra Leone", My.Resources.Sierra_Leone)
            Me.Add("Singapore", My.Resources.Singapore)
            Me.Add("Slovakia", My.Resources.Slovakia)
            Me.Add("Slovenia", My.Resources.Slovenia)
            Me.Add("Soloman Islands", My.Resources.Soloman_Islands)
            Me.Add("Somalia", My.Resources.Somalia)
            Me.Add("South Africa", My.Resources.South_Africa)
            Me.Add("South Georgia", My.Resources.South_Georgia)
            Me.Add("South Korea", My.Resources.South_Korea)
            Me.Add("Spain", My.Resources.Spain)
            Me.Add("Sri Lanka", My.Resources.Sri_Lanka)
            Me.Add("Sudan", My.Resources.Sudan)
            Me.Add("Suriname", My.Resources.Suriname)
            Me.Add("Swaziland", My.Resources.Swaziland)
            Me.Add("Syria", My.Resources.Syria)
            Me.Add("Taiwan", My.Resources.Taiwan)
            Me.Add("Tajikistan", My.Resources.Tajikistan)
            Me.Add("Tanzania", My.Resources.Tanzania)
            Me.Add("Thailand", My.Resources.Thailand)
            Me.Add("Tibet", My.Resources.Tibet)
            Me.Add("Togo", My.Resources.Togo)
            Me.Add("Tonga", My.Resources.Tonga)
            Me.Add("Trinidad and Tobago", My.Resources.Trinidad_and_Tobago)
            Me.Add("Tunisia", My.Resources.Tunisia)
            Me.Add("Turkey", My.Resources.Turkey)
            Me.Add("Turkmenistan", My.Resources.Turkmenistan)
            Me.Add("Turks and Caicos Islands", My.Resources.Turks_and_Caicos_Islands)
            Me.Add("Tuvalu", My.Resources.Tuvalu)
            Me.Add("UAE", My.Resources.UAE)
            Me.Add("Uganda", My.Resources.Uganda)
            Me.Add("Ukraine", My.Resources.Ukraine)
            Me.Add("United Kingdom", My.Resources.United_Kingdom)
            Me.Add("United States of America", My.Resources.United_States_of_America)
            Me.Add("Uruguay", My.Resources.Uruguay)
            Me.Add("US Virgin Islands", My.Resources.US_Virgin_Islands)
            Me.Add("Uzbekistan", My.Resources.Uzbekistan)
            Me.Add("Vanuatu", My.Resources.Vanuatu)
            Me.Add("Vatican City", My.Resources.Vatican_City)
            Me.Add("Venezuela", My.Resources.Venezuela)
            Me.Add("Vietnam", My.Resources.Vietnam)
            Me.Add("Wallis and Futuna", My.Resources.Wallis_and_Futuna)
            Me.Add("Yemen", My.Resources.Yemen)
            Me.Add("Zambia", My.Resources.Zambia)
            Me.Add("Zimbabwe", My.Resources.Zimbabwe)
    
        End Sub
    End Class
    Here is an example on how to use it. Add a new form, a combobox, and a picturebox. Just set the picturebox's size mode to zoom.
    Code:
    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim count As New Countries
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For Each key As String In count.Keys
                ComboBox1.Items.Add(key)
            Next
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim str As String = ComboBox1.Text
            If count.ContainsKey(str) Then
                PictureBox1.Image = count(str)
            End If
        End Sub
    End Class
    Last edited by dday9; Mar 27th, 2013 at 04:44 PM.

  2. #2
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    193

    Re: Class For All Countries with their flags

    Thank you so much, What an awesome job.. I was crossing my fingers for this to work! And I appereciate your time and efforts creating it..
    I really tried hard to add it into my project! I am using a Label, to grab the Country-Name from a website, and then I try to convert t
    to a Country-Flag Image, but fails.

    This my Label Code:
    Label5.Text = GetFlag(TextBox1.Text, "country")
    Short Explanation: TextBox1 is for the username that I type in, then it after clicking Submit, it gets me the Country-name in Label5. So how can I make it fit with your project, Liks if my Label5.Text returns back with the Country name: "Germany", it should then replace the text "Germany" with a Flag image.. Hope you could give me a Short Description to change the code to work with Labels.

    Thank you for your hard work in this..
    Last edited by Miklogak; Mar 14th, 2013 at 12:29 AM.

    A huge thanks to the Great Devs on vBForums who has been helping others for YEARS, and almost everyday! They make this forum worth visiting over and over again! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident and those I forgot to mention!

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,817

    Re: Class For All Countries with their flags

    I would use just a simple conditional stament kinda like how you asked the question:
    Code:
    If count.ContainsKey(Label5.Text) Then
          PictureBox1.Image = count(Label5.Text)
    End If
    That says if the dictionary contains, say Germany, then set Picturebox1's image to Germany's value.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    4,987

    Re: Class For All Countries with their flags

    Quote Originally Posted by dday9 View Post
    It takes a while for the items to be added to the dictionary, it should probolly be done in a seperate thread, but I'm just to lazy to do it.
    It takes about 1/2 a second to load them all which is not bad. I don't think it warrants multi-threading. The effort is more than the gain in this case.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  5. #5
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    193

    Re: Class For All Countries with their flags

    Quote Originally Posted by dday9 View Post
    I would use just a simple conditional stament kinda like how you asked the question:
    Code:
    If count.ContainsKey(Label5.Text) Then
          PictureBox1.Image = count(Label5.Text)
    End If
    That says if the dictionary contains, say Germany, then set Picturebox1's image to Germany's value.
    Thanks a LOT for all the work you put in this Class and I know already I will be using this a lot in future..

    -- New Updates:
    I am back after a long time of trying to see if I can get it , I still cant get anything to show up in the PictureBox!
    I have assigned everything as I should,,, And below is my Button Click code:

    Button Click Code:
    Dim count As New Countries
    If count.ContainsKey(Label11.Text) Then
    PictureBox16.Image = count(Label11.Text)
    End If

    Ps. right now I tried with a TextBox.Text also, and again I get the Country name to show up, but no Image in Picturebox

    And When I click on the button, i get the exact country name showen up in Label11.Text.. I think still there are missing something.
    Hope I can help if there are any another way to try........ Thanks Guys
    Last edited by Miklogak; Mar 14th, 2013 at 06:25 PM.

    A huge thanks to the Great Devs on vBForums who has been helping others for YEARS, and almost everyday! They make this forum worth visiting over and over again! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident and those I forgot to mention!

  6. #6
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,244

    Re: Class For All Countries with their flags

    Try setting the BackgroundImage instead?

  7. #7

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,817

    Re: Class For All Countries with their flags

    I would set a breakpoint and debug. What I'm assuming what's happening is Label11's text isn't matching with a country in the dictionary, even though it seems as though it should. But set up a breakpoint and check if the IF statement gets fired. Alternatively you could add an else and do something along these lines:
    Code:
    Dim count As New Countries
        If count.ContainsKey(Label11.Text) Then
           PictureBox16.Image = count(Label11.Text)
        Else
           MessageBox.Show(Label11.Text & " isn't a country in my dictionary.")
        End If

  8. #8
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    193

    Re: Class For All Countries with their flags

    @formlesstree4, I did try that also, didnt work out either..... But thanks for the tip...

    @dday9, Thanks a lot for the alternative way, and I can now confirm that I get the country names in the MSGBOX S appearing and saying "Isnt a country in my dictionary"! I tested it with several other country names, and I kept checking them over and over again, but non of the Country names would make the Images appear!

    I had to use a different code, and instead I added all the country flags as an IF statement below my button.

    But what am I doing wrong? Am I missing something that cant make the images appear, or maybe the code should be approached or made in a different way...

    And here is what I have done to set the country flags up I have ofcourse created added the Class "Countries" and then added the code you provided

    This code here:
    Dim count As New Countries
    If count.ContainsKey(Label11.Text) Then
    PictureBox17.BackgroundImage = count(Label11.Text)
    Else
    MessageBox.Show(Label11.Text & " isn't a country in my dictionary.")
    End If
    Thanks a lot for following up on this Dday............. I cant wait for us to fix this issue!
    Last edited by Miklogak; Mar 17th, 2013 at 01:01 AM.

    A huge thanks to the Great Devs on vBForums who has been helping others for YEARS, and almost everyday! They make this forum worth visiting over and over again! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident and those I forgot to mention!

  9. #9

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,817

    Re: Class For All Countries with their flags

    The only thing that I can think of is if you're getting the country from a different source, I think I remember you saying you're getting them from a website, then the way that the country is being loaded into the label is different that the way the country is stored in the dictionary. Something that I would try is still set up a breakpoint at the label11.text and check if there are any extra spaces or any sort of abnormality, because that's the most probable cause. You can always get rid of white spaces by String.Trim.

  10. #10
    Addicted Member iactulip's Avatar
    Join Date
    Feb 2009
    Location
    Dubai UAE
    Posts
    139

    Re: Class For All Countries with their flags

    flags file not found dear please upload file again

  11. #11

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,817

    Re: Class For All Countries with their flags

    Quote Originally Posted by iactulip View Post
    flags file not found dear please upload file again
    I went ahead and reposted a new link with SkyDrive

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.