Currency Converter
1. Pertama seperti biasa yaitu buat new project seperti gambar dibawah ini.
Disini saya memakai Windows Forms App (.NET Framework) dengan Visual Basic, namun bisa juga memakai dengan C#. Setelah memilih, klik next. Kemudian beri nama project kalian, lalu klik create.
2. Desain Form
3. Source Code
using System; using System.Net; using Newtonsoft.Json.Linq; using System.Windows.Forms; namespace currencycorverter { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string[] getCurrencyTags() { return new string[] { "EUR", "USD", "JPY", "IDR", "AUD", "CAD", "JPY", "SGD", "PHP", "MYR", "CNY" }; } private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.AddRange(getCurrencyTags()); comboBox2.Items.AddRange(getCurrencyTags()); } private void label1_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string url = string.Format( "https://api.exchangeratesapi.io/latest?base={0}&symbols={1}", comboBox1.SelectedItem, comboBox2.SelectedItem ); dynamic res = JObject.Parse(new WebClient().DownloadString(url)); float rate = (float)res.rates[comboBox2.SelectedItem]; label2.Text = (float.Parse(textBox1.Text) * rate).ToString("0.00"); textBox2.Text = "DIKIRI NGAB"; } } }
Jika sudah maka program dapat dijalankan dan hasilnya seperti ini
Comments
Post a Comment