“Currency Exchange” dengan Visual Basic.NET 2010
Karena penasaran dengan konversi mata uang yang terdapat pada bagian Finance Detik.com akhirnya saya coba buat dengan Visual Basic.NET dan kebetulan selagi surfing di internet saya ketemu dengan situs yang membuat aplikasi serupa. Tertarik dengan design formnya lalu saya adaptasikan pada pemrograman aplikasi ini. Jika sempat saya coba adaptasikan ke dalam Visual Basic 6.0 dan Delphi 2010. Namun karena banyak pekerjaan yang harus saya diperioritaskan maka tidak bisa saya postingkan seperti biasanya.
1. Jalankan terlebih dahulu aplikasi Visual Basic 2010
2. Pada tabulasi “Start Page” pilih “New Project” atau bisa juga dengan menekan tombol “Ctrl + N” pada keyboard
3. Pada jendela “New Project” pilih “Windows Forms Application” kemudian tekan tombol “OK”
4. Berikut setingan kontrol properti yang terdapat pada aplikasi ini:
Object | Name | Properties | Setting |
Form | Form1 | Font Form Border Style Maximize Box Start Position Text | Tahoma; 10pt Fixed Single False Center Screen Currency Exchange |
Label | Label1 | Text | Nominal: |
Label | lblDisplay1 | Text | (Empty) |
Text Box | txtInput | Text Align | Right |
Label | Label2 | Text | = |
Label | lblDisplay2 | Text | (Empty) |
Text Box | txtOutput | Text Align | Right |
Label | Label5 | Text | From: |
Combo Box | cmbFrom | Drop Down Style | Drop Down List |
Label | Label6 | Text | To: |
Combo Box | cmbFrom | Drop Down Style | Drop Down List |
Button | btnConvert | Text | Convert |
Button | btnExit | Text | E&xit |
5. Berikut event code program ini:
Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MsgBox("Exit the Aplication?", vbYesNo + vbQuestion, "Confirmation") = vbNo Then
If e.CloseReason = CloseReason.UserClosing Then
e.Cancel = True
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
AddItem()
End Sub
Private Sub cmbFrom_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmbFrom.SelectedIndexChanged
If cmbFrom.SelectedItem.Equals("IDR (Indonesian - Rupiah)") Then
lblDisplay1.Text = "Rp"
txtInput.Focus()
ElseIf cmbFrom.SelectedItem.Equals("USD (United State - Dollar)") Then
lblDisplay1.Text = "$"
txtInput.Focus()
ElseIf cmbFrom.SelectedItem.Equals("JPY (Japan - Yen)") Then
lblDisplay1.Text = "¥"
txtInput.Focus()
End If
End Sub
Private Sub cmbTo_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmbTo.SelectedIndexChanged
If cmbTo.SelectedItem.Equals("IDR (Indonesian - Rupiah)") Then
lblDisplay2.Text = "= Rp"
txtInput.Focus()
ElseIf cmbTo.SelectedItem.Equals("USD (United State - Dollar)") Then
lblDisplay2.Text = "= $"
txtInput.Focus()
ElseIf cmbTo.SelectedItem.Equals("JPY (Japan - Yen)") Then
lblDisplay2.Text = "= ¥"
txtInput.Focus()
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnExit.Click
Close()
End Sub
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnConvert.Click
Dim USDtoIDR As Decimal = txtInput.Text * 12375.0
Dim IDRtoUSD As Decimal = txtInput.Text / 12375.0
Dim JPYtoIDR As Decimal = txtInput.Text * 118.65
Dim IDRtoJPY As Decimal = txtInput.Text / 118.65
Dim USDtoJPY As Decimal = txtInput.Text * 104.3
Dim JPYtoUSD As Decimal = txtInput.Text / 104.3
If btnConvert.Text = "Convert" Then
If cmbFrom.SelectedItem.Equals("USD (United State - Dollar)") And _
cmbTo.SelectedItem.Equals("IDR (Indonesian - Rupiah)") Then
txtOutput.Text = USDtoIDR.ToString
ElseIf cmbFrom.SelectedItem.Equals("IDR (Indonesian - Rupiah)") And _
cmbTo.SelectedItem.Equals("USD (United State - Dollar)") Then
txtOutput.Text = IDRtoUSD.ToString
ElseIf cmbFrom.SelectedItem.Equals("JPY (Japan - Yen)") And _
cmbTo.SelectedItem.Equals("IDR (Indonesian - Rupiah)") Then
txtOutput.Text = JPYtoIDR.ToString
ElseIf cmbFrom.SelectedItem.Equals("IDR (Indonesian - Rupiah)") And _
cmbTo.SelectedItem.Equals("JPY (Japan - Yen)") Then
txtOutput.Text = IDRtoJPY.ToString
ElseIf cmbFrom.SelectedItem.Equals("USD (United State - Dollar)") And _
cmbTo.SelectedItem.Equals("JPY (Japan - Yen)") Then
txtOutput.Text = USDtoJPY.ToString
ElseIf cmbFrom.SelectedItem.Equals("JPY (Japan - Yen)") And _
cmbTo.SelectedItem.Equals("USD (United State - Dollar)") Then
txtOutput.Text = JPYtoUSD.ToString
End If
If cmbFrom.SelectedItem.Equals("IDR (Indonesian - Rupiah)") And _
cmbTo.SelectedItem.Equals("IDR (Indonesian - Rupiah)") Or _
cmbFrom.SelectedItem.Equals("USD (United State - Dollar)") And _
cmbTo.SelectedItem.Equals("USD (United State - Dollar)") Or _
cmbFrom.SelectedItem.Equals("JPY (Japan - Yen)") And _
cmbTo.SelectedItem.Equals("JPY (Japan - Yen)") Then
txtOutput.Text = txtInput.Text
End If
btnConvert.Text = "New"
txtInput.Enabled = False
txtOutput.Enabled = False
cmbFrom.Enabled = False
cmbTo.Enabled = False
txtInput.BackColor = Color.FromKnownColor(KnownColor.Window)
txtOutput.BackColor = Color.FromKnownColor(KnownColor.Window)
cmbFrom.BackColor = Color.FromKnownColor(KnownColor.Window)
cmbTo.BackColor = Color.FromKnownColor(KnownColor.Window)
ElseIf btnConvert.Text = "New" Then
btnConvert.Text = "Convert"
txtInput.Clear()
txtOutput.Clear()
cmbFrom.Items.Clear()
cmbTo.Items.Clear()
lblDisplay1.Text = ""
lblDisplay2.Text = "="
txtInput.Enabled = True
txtOutput.Enabled = True
cmbFrom.Enabled = True
cmbTo.Enabled = True
txtInput.Focus()
AddItem()
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyPressEventArgs) Handles txtInput.KeyPress
If Not (e.KeyChar >= ChrW(Keys.D0) And e.KeyChar <= ChrW(Keys.D9) Or _
e.KeyChar = ChrW(45) Or e.KeyChar = ChrW(46) Or e.KeyChar = ChrW(Keys.Back) Or _
e.KeyChar = ChrW(Keys.Return)) Then
e.KeyChar = ChrW(0)
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyPressEventArgs) Handles txtOutput.KeyPress
If Not (e.KeyChar >= ChrW(Keys.D0) And e.KeyChar <= ChrW(Keys.D9) Or _
e.KeyChar = ChrW(45) Or e.KeyChar = ChrW(46) Or e.KeyChar = ChrW(Keys.Back) Or _
e.KeyChar = ChrW(Keys.Return)) Then
e.KeyChar = ChrW(0)
End If
End Sub
Private Sub AddItem()
Dim Tmplst As Integer
Dim strCurrency As String() = {"IDR (Indonesian - Rupiah)", _
"USD (United State - Dollar)", _
"JPY (Japan - Yen)"}
cmbFrom.Items.AddRange(strCurrency)
For Tmplst = 0 To (cmbFrom.Items.Count - 1)
cmbTo.Items.Add(cmbFrom.Items.Item(Tmplst))
Next
End Sub
End Class
6. Klik tombol “Start Debuging” atau tekan tombol “F5” pada Keyboard untuk menjalankan aplikasi.
Label: VB.NET
2 Komentar:
Great article.
I rather do not have to use such things, because when I want to check the exchange rate on the website https://conotoxia.com/money-transfer I can do it right away. That is why I am of the opinion that it is worth using an online currency exchange office for online currency exchange.
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda