Results 1 to 8 of 8

Thread: Inserting flags based on user-input

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    33

    Inserting flags based on user-input

    I have a small software inside which there is a facility to select which country, Now i have a database of around 150 flags uploaded to My.Resources.

    I first started using this code.

    Code:
           Select Case TextBoxCountry.Text
    
                  Case is = "England"
                  PictureBox.image = My.Resources.England
                  Case is = "USA"
                  PictureBox.image = My.Resources.USA
                  Case is = "Austraila"
                  PictureBox.image = My.Resources.Australia
    and soo on,

    But do i have to do this to all the 150 flags?? isn there a simple way??

    I have named all the resource images to the names of their country exactly. Eg: India.jpg, Australia.jpg etc

    Cant i use this somehow??

    And is there a way that i can make it case-insensitive so that if the user enters it in improper case also it will recognise it??

    Thank You.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Inserting flags based on user-input

    I have a class in my signature where I handle just that. It's titled "Country Flags", take a look at that and see if that helps you out.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Inserting flags based on user-input

    Good work dday, but my initial though would be to load the data into a database.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Inserting flags based on user-input

    Good work dday
    Thank you :]
    my initial though would be to load the data into a database.
    See that's what I thought I should've done, but I figured the dictionary was universal enough to apply to everyone. I thought, what if one was using MySQL, Oracle, or Access, I couldn't just use SQLCompaq(which is what I've started using).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Inserting flags based on user-input

    no need for an extensive select case block or utilizing a database. 1 line:

    Code:
    PictureBox1.Image = DirectCast(My.Resources.ResourceManager.GetObject(StrConv(TextBoxCountry.Text, VbStrConv.ProperCase)), Bitmap)

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    33

    Re: Inserting flags based on user-input

    Quote Originally Posted by .paul. View Post
    no need for an extensive select case block or utilizing a database. 1 line:

    Code:
    PictureBox1.Image = DirectCast(My.Resources.ResourceManager.GetObject(StrConv(TextBoxCountry.Text, VbStrConv.ProperCase)), Bitmap)


    Thank You very much It worked.

    I have one more doubt.
    Now to enter the name of the country i have given the user an InputBox, But what i want is a Something like a suggestion box that suggests the name of the country as the start typing the first few letters, so that they will be able to select a country rather than type in a name for which they might not kno the correct spelling.
    Im a 3 month old new bee in this field, Please help me out if you can

  7. #7
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: Inserting flags based on user-input

    Have a look at this thread on VBForums, particularly Post #4 which also gives a link to MSDN documentation.
    If you want to use a TextBox, the MSDN documentation should be especially useful.

  8. #8
    Junior Member
    Join Date
    Apr 2013
    Posts
    17

    Re: Inserting flags based on user-input

    I think that you have to implement it for all 150 flags, there is no other option for you.

Posting Permissions

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



Click Here to Expand Forum to Full Width