Check Country's Currency using Visual Basic.Net
Posted by Samath
Last Updated: December 30, 2016

This program is used to find out which currency is used in a particular country.

Code:

Public Class Form1
    Dim cbox As New ComboBox With {.Sorted = True}
    Dim Countryname, Currencyname, Currencysymbol, CurrentComputerCulture As String
    Dim CountryIndex As Int32

    Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
        Me.Close()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CurrentComputerCulture = Globalization.RegionInfo.CurrentRegion.DisplayName
        For Each Country In Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.InstalledWin32Cultures)
            'change region
            My.Application.ChangeCulture(Country.Name)
            Countryname = Globalization.RegionInfo.CurrentRegion.DisplayName
            If ComboBox1.Items.Contains(Countryname) = False Then
                'add country name
                ComboBox1.Items.Add(Countryname)
                cbox.Items.Add(Countryname & "/" & Globalization.RegionInfo.CurrentRegion.CurrencyNativeName & " = " & Globalization.RegionInfo.CurrentRegion.CurrencySymbol)
            End If
            'clear cached data
            My.Application.Culture.ClearCachedData()
        Next
        If cbox.Items.Count > 0 Then
            CountryIndex = ComboBox1.FindString(CurrentComputerCulture)
            cbox.SelectedIndex = CountryIndex
            ComboBox1.SelectedIndex = CountryIndex
        End If
    End Sub
    Dim i As Int32
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCheck.Click
        i = ComboBox1.FindString(ComboBox1.Text)
        cbox.SelectedIndex = i
        Currencyname = cbox.SelectedItem.ToString.Remove(0, cbox.SelectedItem.ToString.IndexOf("/") + 1)
        Currencyname = Currencyname.Substring(0, Currencyname.IndexOf("="))
        Currencysymbol = cbox.SelectedItem.ToString.Remove(0, cbox.SelectedItem.ToString.IndexOf("=") + 1).Trim
        LabelInfo.Text = ComboBox1.Text & " currency is " & Currencyname & Environment.NewLine & "Currency Symbol: " & Currencysymbol

    End Sub
End Class

 

Related Content