Simple CALCULATOR - VB.NET
Dear
agan-agan para pecinta koding.. lagi-lagi berawal dari tugas kuliah
baru-baru ini, dapet tugas buat perhitungan matematika dasar. mari kita
belajar bersama-sama lagi. buat yang sudah master mohon petunjuknya,
mungkin aplikasi ini terlalu dasar.
seperti pada
tutorial sebelumnya silahkan dipersiapkan form kalkulator anda ya paling
tidak sama kayak punya saya. ga perlu buat 2 form ya !! itu cuma buat
membedakan saja kondisi "ON" atau "OFF" saja.
nah ini dia kodingnya :
Public Class KALKULATOR372Dim STR_01 As Double
Dim STR_02 As Double
Dim STR_03 As String
Private Sub BACKSPACE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BACKSPACE.Click
Dim X As New Integer
If (TxtLAYAR.Text.Length > 0) Then
X = TxtLAYAR.Text.Length
TxtLAYAR.Text = TxtLAYAR.Text.Remove(X - 1, 1)
End If
End Sub
Private Sub ANGKA_01_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_01.Click
TxtLAYAR.Text += ANGKA_01.Text
End Sub
Private Sub ANGKA_02_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_02.Click
TxtLAYAR.Text += ANGKA_02.Text
End Sub
Private Sub ANGKA_03_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_03.Click
TxtLAYAR.Text += ANGKA_03.Text
End Sub
Private Sub ANGKA_04_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_04.Click
TxtLAYAR.Text += ANGKA_04.Text
End Sub
Private Sub ANGKA_05_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_05.Click
TxtLAYAR.Text += ANGKA_05.Text
End Sub
Private Sub ANGKA_06_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_06.Click
TxtLAYAR.Text += ANGKA_06.Text
End Sub
Private Sub ANGKA_07_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_07.Click
TxtLAYAR.Text += ANGKA_07.Text
End Sub
Private Sub ANGKA_08_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_08.Click
TxtLAYAR.Text += ANGKA_08.Text
End Sub
Private Sub ANGKA_09_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_09.Click
TxtLAYAR.Text += ANGKA_09.Text
End Sub
Private Sub ANGKA_NOL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_NOL.Click
TxtLAYAR.Text += ANGKA_NOL.Text
End Sub
Private Sub ANGKA_00_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ANGKA_00.Click
TxtLAYAR.Text += ANGKA_00.Text
End Sub
Private Sub SAMADENGAN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SAMADENGAN.Click
STR_02 = Val(TxtLAYAR.Text)
If STR_03 = "--" Then
TxtLAYAR.Text = STR_01 - STR_02
ElseIf STR_03 = "+" Then
TxtLAYAR.Text = STR_01 + STR_02
ElseIf STR_03 = "X" Then
TxtLAYAR.Text = STR_01 * STR_02
ElseIf STR_03 = "/" Then
TxtLAYAR.Text = STR_01 / STR_02
End If
End Sub
Private Sub CLEAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CLEAR.Click
TxtLAYAR.Text = ""
STR_03 = ""
End Sub
Private Sub KURANG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KURANG.Click
STR_01 = Val(TxtLAYAR.Text)
TxtLAYAR.Text = ""
STR_03 = KURANG.Text
End Sub
Private Sub TAMBAH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TAMBAH.Click
STR_01 = Val(TxtLAYAR.Text)
TxtLAYAR.Text = ""
STR_03 = TAMBAH.Text
End Sub
Private Sub KALI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KALI.Click
STR_01 = Val(TxtLAYAR.Text)
TxtLAYAR.Text = ""
STR_03 = KALI.Text
End Sub
Private Sub BAGI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BAGI.Click
STR_01 = Val(TxtLAYAR.Text)
TxtLAYAR.Text = ""
STR_03 = BAGI.Text
End Sub
Private Sub TITIK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TITIK.Click
TxtLAYAR.Text += TITIK.Text
End Sub
Private Sub BUTTON_NONAKTIF()
CLEAR.Enabled = False
BACKSPACE.Enabled = False
ANGKA_01.Enabled = False
ANGKA_02.Enabled = False
ANGKA_03.Enabled = False
ANGKA_04.Enabled = False
ANGKA_05.Enabled = False
ANGKA_06.Enabled = False
ANGKA_07.Enabled = False
ANGKA_08.Enabled = False
ANGKA_09.Enabled = False
ANGKA_NOL.Enabled = False
ANGKA_00.Enabled = False
KALI.Enabled = False
BAGI.Enabled = False
TAMBAH.Enabled = False
KURANG.Enabled = False
TITIK.Enabled = False
SAMADENGAN.Enabled = False
End Sub
Private Sub BUTTON_AKTIF()
CLEAR.Enabled = True
BACKSPACE.Enabled = True
ANGKA_01.Enabled = True
ANGKA_02.Enabled = True
ANGKA_03.Enabled = True
ANGKA_04.Enabled = True
ANGKA_05.Enabled = True
ANGKA_06.Enabled = True
ANGKA_07.Enabled = True
ANGKA_08.Enabled = True
ANGKA_09.Enabled = True
ANGKA_NOL.Enabled = True
ANGKA_00.Enabled = True
KALI.Enabled = True
BAGI.Enabled = True
TAMBAH.Enabled = True
KURANG.Enabled = True
TITIK.Enabled = True
SAMADENGAN.Enabled = True
End Sub
Private Sub KALKULATOR372_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call BUTTON_NONAKTIF()
End Sub
Private Sub ONOFF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ONOFF.Click
If ONOFF.Text = "ON" Then
Call BUTTON_AKTIF()
ONOFF.Text = "OFF"
ElseIf ONOFF.Text = "OFF" Then
Call BUTTON_NONAKTIF()
ONOFF.Text = "ON"
TxtLAYAR.Text = ""
End If
End Sub
End Class