Determine Country Currency and Symbol in VB.NET

This tutorial will teach you how to create a program that will first display all the countries in the world and will determine the currency of the country inputted using vb.net. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add only one ComboBox named ComboBox1 to view all the countries in the world, a Button named ButtonCheck to determine the currency and symbol of the country, and a Label named LabelInfo for displaying the currency and symbol of the country. You must design your interface like this: output 3. Now, let's do the coding. Initalize first the following variables:
  1. ' for sorting the combobox
  2.     Dim cbox As New ComboBox With {.Sorted = True}
  3. ' for the country, currency name and symbol
  4.     Dim Countryname, Currencyname, Currencysymbol, CurrentComputerCulture As String
  5. ' country index in the combobox
  6.     Dim CountryIndex As Int32
  7. ' currency index
  8.     Dim i As Int32
In your Form_Load, put this code below for displaying the countries in the ComboBox.
  1.  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         CurrentComputerCulture = Globalization.RegionInfo.CurrentRegion.DisplayName
  3.         For Each Country In Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.InstalledWin32Cultures)
  4.             'change region
  5.             My.Application.ChangeCulture(Country.Name)
  6.             Countryname = Globalization.RegionInfo.CurrentRegion.DisplayName
  7.             If ComboBox1.Items.Contains(Countryname) = False Then
  8.                 'add country name
  9.                 ComboBox1.Items.Add(Countryname)
  10.                 cbox.Items.Add(Countryname & "/" & Globalization.RegionInfo.CurrentRegion.CurrencyNativeName & " = " & Globalization.RegionInfo.CurrentRegion.CurrencySymbol)
  11.             End If
  12.             'clear cached data
  13.             My.Application.Culture.ClearCachedData()
  14.         Next
  15.         If cbox.Items.Count > 0 Then
  16.             CountryIndex = ComboBox1.FindString(CurrentComputerCulture)
  17.             cbox.SelectedIndex = CountryIndex
  18.             ComboBox1.SelectedIndex = CountryIndex
  19.         End If
  20.     End Sub
For determining the country's currency and symbol put this code in your ButtonCheck_click.
  1.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCheck.Click
  2. 'get the chosen country in the combobox
  3.         i = ComboBox1.FindString(ComboBox1.Text)
  4.         cbox.SelectedIndex = i
  5. ' get the currency name
  6.         Currencyname = cbox.SelectedItem.ToString.Remove(0, cbox.SelectedItem.ToString.IndexOf("/") + 1)
  7.         Currencyname = Currencyname.Substring(0, Currencyname.IndexOf("="))
  8. ' get the currency symbol
  9.         Currencysymbol = cbox.SelectedItem.ToString.Remove(0, cbox.SelectedItem.ToString.IndexOf("=") + 1).Trim
  10.         LabelInfo.Text = ComboBox1.Text & " currency is " & Currencyname & Environment.NewLine & "Currency Symbol: " & Currencysymbol
  11.  
  12.     End Sub

Output:

output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment