Kali Ini Saya Akan Berbagi Ilmu Tentang Membuat Kalkulator Sederhana Dengan Vb.net Segala Versi Mau Vb.net2010 Atau Vb.net 2008. Ok Kita LangSung Eksekusi Aja Ya Teman !!
Kalkulator Sederhana Dengan Kode Nya , Ini Untuk Latihan Yang masih Awal Tentang Vb.net Termasuk Juga Saya :
1. Buka Microsoft Visual Studio 2010 ultimate/2008
2. Pilih Windows Form Application
3. Buat :
-17 buah Button (btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btnTitik, btnHasil, btnKali, btnTambah, btnKurang, btnBagi, btnClear)
- 1 buah Textbox pada Form
4. Edit Text property pada tiap Button sehingga tampilan seperti gambar dibawah.
5. Double klik pada form lalu masukkan kode berikut :
- Dim operand1 As Double
- Dim [operator] As String
- Dim baru As Boolean = True
- Dim temp As Double
- Dim operand2 As Double
6. Double klik pada button 0 ketikkan kode
- Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
- btn0.Click, btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click
- TextBox1.Text = TextBox1.Text & sender.text
- End Sub
7. Masukkan kode berikut pada button Tambah
- Private Sub btnTamah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTambah.Click
- If baru = True Then
- operand1 = Val(TextBox1.Text)
- TextBox1.Text = ""
- TextBox1.Focus()
- [operator] = "+"
- ElseIf baru = False Then
- If [operator] = "+" Then
- temp = operand1 + Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "+"
- ElseIf [operator] = "-" Then
- temp = operand1 - Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "+"
- ElseIf [operator] = "x" Then
- temp = operand1 * Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "+"
- ElseIf [operator] = ":" Then
- temp = operand1 / Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "+"
- End If
- End If
- baru = False
- End Sub
8. Masukkan Kode Berikut Pada Button Kurang
- Private Sub btnKurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKurang.Click
- If baru = True Then
- operand1 = Val(TextBox1.Text)
- TextBox1.Text = ""
- TextBox1.Focus()
- [operator] = "-"
- ElseIf baru = False Then
- If [operator] = "+" Then
- temp = operand1 + Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "-"
- ElseIf [operator] = "-" Then
- temp = operand1 - Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "-"
- ElseIf [operator] = "x" Then
- temp = operand1 * Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "-"
- ElseIf [operator] = ":" Then
- temp = operand1 / Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "-"
- End If
- End If
- baru = False
- End Sub
9. Kode Berikut pada button Kali
- Private Sub btnKali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKali.Click
- If baru = True Then
- operand1 = Val(TextBox1.Text)
- TextBox1.Text = ""
- TextBox1.Focus()
- [operator] = "x"
- ElseIf baru = False Then
- If [operator] = "+" Then
- temp = operand1 + Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "x"
- ElseIf [operator] = "-" Then
- temp = operand1 - Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "x"
- ElseIf [operator] = ";" Then
- temp = operand1 / Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "x"
- ElseIf [operator] = "x" Then
- temp = operand1 * Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = "x"
- End If
- End If
- baru = False
- End Sub
10. Kode Berikut Pada button Bagi
- Private Sub btnBagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBagi.Click
- If baru = True Then
- operand1 = Val(TextBox1.Text)
- TextBox1.Text = ""
- TextBox1.Focus()
- [operator] = ":"
- ElseIf baru = False Then
- If [operator] = "+" Then
- temp = operand1 + Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = ":"
- ElseIf [operator] = "-" Then
- temp = operand1 - Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = ":"
- ElseIf [operator] = "x" Then
- temp = operand1 * Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = ":"
- ElseIf [operator] = ":" Then
- temp = operand1 / Val(TextBox1.Text)
- operand1 = temp
- TextBox1.Text = ""
- [operator] = ":"
- End If
- End If
- baru = False
- End Sub
11. Kode berikut pada button hasil
- Dim hasil As Double
- operand2 = Val(TextBox1.Text)
- Select Case [operator]
- Case "+"
- hasil = operand1 + operand2
- TextBox1.Text = hasil.ToString
- baru = True
- Case "-"
- hasil = operand1 - operand2
- TextBox1.Text = hasil.ToString
- Case ":"
- hasil = operand1 / operand2
- TextBox1.Text = hasil.ToString
- Case "x"
- hasil = operand1 * operand2
- TextBox1.Text = hasil.ToString
- baru = True
- End Select
- TextBox1.Text = hasil.ToString
12. Kode berikut pada button titik
- Private Sub btnTitik_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTitik.Click
- If InStr(TextBox1.Text, ".") > 0 Then
Exit Sub
- Else
TextBox1.Text = TextBox1.Text & "."
End If
- End Sub
13. Dan terakhir pada button Clear
- Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
- TextBox1.Text = ""
- operand1 = 0
- temp = 0
- baru = True
- End Sub
Sekian Teman Semoga Bermanfaat bagi Teman _ Teman Semuanya...
nitip link gan
BalasHapushttp://air-team.pe.hu/
http://muhammad-4lief.blogspot.co.id/