Source Code Aplikasi Kalkulator MenggunakanVB.Net
-Pengenalan Komponen Toolbox
-Pengenalan form, variable, void
- pengenalan fungsi2 matematika
Latihan 1. Kalkulator matematika menggunakan Button
1
========================================================================
Public Class kalkulator1
Private Sub txtTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTambah.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 + b2
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtKurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKurang.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 - b2
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtKali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKali.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 * b2
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtBagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBagi.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 / b2
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtPangkat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPangkat.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 ^ b2
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtSin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSin.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Sin(b1 / b2)
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtCos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCos.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Cos(b1 / b2)
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtTan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTan.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Tan(b1 / b2)
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtAkar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAkar.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Sqrt(b1 * b2)
txtHasil.Text = CStr(hs)
End Sub
Private Sub txtLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLog.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Log(b1 / b2)
txtHasil.Text = CStr(hs)
End Sub
Private Sub btnClean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClean.Click
txtBil1.Text = ""
txtBil2.Text = ""
txtHasil.Text = ""
End Sub
Private Sub txtCompere_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCompere.Click
Dim b1, b2 As Double
Dim shs As String
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
If b1 > b2 Then
shs = "bilangan 1 lebih besar dari bilangan 2"
ElseIf b1 < b2 Then
shs = "bilangan 2 lebih besar dari bilangan 1"
Else
shs = "bilangan 1 sama dengan bilangan 2"
End If
txtHasil.Text = shs
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Closet()
End Sub
Private Sub btnMod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMod.Click
Dim b1, b2, hs As Double
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 Mod b2
txtHasil.Text = CStr(hs)
End Sub
End Class
=====================================================================
Latihan 2 Kalkulator mengunakan Combobox
=========================================================================
PublicClassKalkulator2
PrivateSub Kalkulator2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
cmbPilih.Items.Add("Tambah")
cmbPilih.Items.Add("Kurang")
cmbPilih.Items.Add("Kali")
cmbPilih.Items.Add("Bagi")
cmbPilih.Items.Add("Pangkat")
cmbPilih.Items.Add("Akar")
cmbPilih.Items.Add("Mod")
cmbPilih.Items.Add("Sin")
cmbPilih.Items.Add("Cos")
cmbPilih.Items.Add("Tan")
cmbPilih.Items.Add("Log")
cmbPilih.Items.Add("Clear")
cmbPilih.Items.Add("Compare")
EndSub
PrivateSub cmbPilih_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPilih.SelectedIndexChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
If cmbPilih.Text = "Tambah"Then
hs = b1 + b2
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Kurang"Then
hs = b1 - b2
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Kali"Then
hs = b1 * b2
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Bagi"Then
hs = b1 / b2
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Pangkat"Then
hs = b1 ^ b2
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Akar"Then
hs = Math.Sqrt(b1 * b2)
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Mod"Then
hs = b1 Mod b2
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Sin"Then
hs = Math.Sin(b1 / b2)
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Cos"Then
hs = Math.Cos(b1 / b2)
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Tan"Then
hs = Math.Tan(b1 / b2)
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Log"Then
hs = Math.Log(b1 * b2)
txtHasil.Text = CStr(hs)
ElseIf cmbPilih.Text = "Compare"Then
Dim shs AsString
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
If b1 > b2 Then
shs = "bilangan 1 lebih besar dari bilangan 2"
ElseIf b1 < b2 Then
shs = "bilangan 2 lebih besar dari bilangan 1"
Else
shs = "bilangan sama dengan bilangan 2"
EndIf
txtHasil.Text = shs
EndIf
EndSub
PrivateSub txtExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtExit.Click
Close()
EndSub
PrivateSub txtClean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtClean.Click
txtBil1.Text = ""
txtBil2.Text = ""
txtHasil.Text = ""
cmbPilih.Text = ""
EndSub
EndClass
==================================================================
Latihan 3 Kalkulator Menggunakan RadioButton
PublicClassKalkulator_3
PrivateSub txtClean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtClean.Click, Button2.Click
txtBil1.Text = ""
txtBil2.Text = ""
txtHasil.Text = ""
EndSub
PrivateSub radTambah_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTambah.CheckedChanged, RadioButton12.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 + b2
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radKurang_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radKurang.CheckedChanged, RadioButton2.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 - b2
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radKali_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radKali.CheckedChanged, RadioButton3.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 * b2
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radBagi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radBagi.CheckedChanged, RadioButton4.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 / b2
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radPangkat_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radPangkat.CheckedChanged, RadioButton10.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 ^ b2
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radAkar_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radAkar.CheckedChanged, RadioButton11.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Sqrt(b1 * b2)
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radMod_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radMod.CheckedChanged, RadioButton8.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = b1 Mod b2
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radSin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSin.CheckedChanged, RadioButton9.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Sin(b1 / b2)
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radCos_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radCos.CheckedChanged, RadioButton7.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Cos(b1 / b2)
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radTan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTan.CheckedChanged, RadioButton6.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Tan(b1 / b2)
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radLog_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radLog.CheckedChanged, RadioButton5.CheckedChanged
Dim b1, b2, hs AsDouble
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
hs = Math.Log(b1 / b2)
txtHasil.Text = CStr(hs)
EndSub
PrivateSub radCompare_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radCompare.CheckedChanged, RadioButton1.CheckedChanged
Dim b1, b2 AsDouble
Dim shs AsString
b1 = Val(txtBil1.Text)
b2 = Val(txtBil2.Text)
If b1 > b2 Then
shs = "bilangan 1 lebih besar dari bilangan 2"
ElseIf b1 < b2 Then
shs = "bilangan 2 lebih besar dari bilangan 1"
Else
shs = "bilangan sama dengan bilangan 2"
EndIf
txtHasil.Text = shs
EndSub
PrivateSub txtExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtExit.Click, Button1.Click
Close()
EndSub
PrivateSub Kalkulator_3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
lblWaktu.Text = DateTime.Now.ToString("hh:mm:ss")
EndSub
EndSub
EndClass
Posting Komentar untuk "Source Code Aplikasi Kalkulator MenggunakanVB.Net"