Mata Kuliah pemrograman Komputer with Bapak R. Hengki Rahmanto, ST.M.Eng

seperti pada proses pembuatan kalkulator pada postingan sebelumnya. kalkulator inipun tak jauh beda langkah pembuatannya yang membedakan adalah source code yang lebih bannyak

kalkulator temonsoejadi

berikut ini source code selengkapnya ;

Private Hasil As Double
Private Const opnol = 0
Private Const optambah = 1
Private Const opkurang = 2
Private Const opkali = 3
Private Const opbagi = 4
Private operator As Integer
Private nilaibaru As Boolean

pembuatan

Private Sub hapus()
Dim txt As String
Dim min_len As Integer

Private Sub cmd_0_Click()
txtnumber = txtnumber + “0”
End Sub

Private Sub cmd_1_Click()
txtnumber = txtnumber + “1”
End Sub

Private Sub cmd_2_Click()
txtnumber = txtnumber + “2”
End Sub

Private Sub cmd_3_Click()
txtnumber = txtnumber + “3”
End Sub

Private Sub cmd_4_Click()
txtnumber = txtnumber + “4”
End Sub

Private Sub cmd_5_Click()
txtnumber = txtnumber + “5”
End Sub

Private Sub cmd_6_Click()
txtnumber = txtnumber + “6”
End Sub

Private Sub cmd_7_Click()
txtnumber = txtnumber + “7”
End Sub

Private Sub cmd_8_Click()
txtnumber = txtnumber + “8”
End Sub

Private Sub cmd_9_Click()
txtnumber = txtnumber + “9”
End Sub

Private Sub cmd_bagi_Click()
mbutton = 4
mfirst = Val(txtnumber)
txtnumber = “”
End Sub

Private Sub cmd_hasil_Click()
msecond = Val(txtnumber)
Select Case mbutton
Case Is = 1
manswer = mfirst + msecond
Case Is = 2
manswer = mfirst – msecond
Case Is = 3
manswer = mfirst * msecond
Case Is = 4
manswer = mfirst / msecond
End Select
txtnumber = manswer
End Sub

Private Sub cmd_kali_Click()
mbutton = 3
mfirst = Val(txtnumber)
txtnumber = “”
End Sub

Private Sub cmd_kurang_Click()
mbutton = 2
mfirst = Val(txtnumber)
txtnumber = “”
End Sub

Private Sub cmd_tambah_Click()
mbutton = 1
mfirst = Val(txtnumber)
txtnumber = “”
End Sub

Private Sub cmdAngka_Click(Index As Integer)
If nilaibaru Then
txtdisplay.Text = Format$(Index)
nilaibaru = False
Else
txtdisplay.Text = _
txtdisplay.Text & Format$(Index)
End If
End Sub

Private Sub cmdClear_Click()
cmdClearEntry_Click
Hasil = 0
operator = opnol
End Sub

Private Sub cmdClearEntry_Click()
txtdisplay.Text = “”
End Sub

Private Sub cmdKoma_Click()
If InStr(txtdisplay.Text, “.”) Then
Beep
Else
If nilaibaru Then
txtdisplay.Text = “.”
nilaibaru = False
Else
txtdisplay.Text = txtdisplay.Text & “.”
End If
End If
End Sub

Private Sub cmdOperator_Click(Index As Integer)

cmdSamaDengan_Click
operator = Index

nilaibaru = True
End Sub

Private Sub cmdPlusMinus_Click()
If nilaibaru Then
txtdisplay.Text = “-”
ElseIf Left$(txtdisplay.Text, 1) = “-” Then
txtdisplay.Text = Right$(txtdisplay.Text, 2)
Else
txtdisplay.Text = “-” & txtdisplay.Text
End If
End Sub

Private Sub cmdSamaDengan_Click()
Dim hasilbaru As Double

If txtdisplay.Text = “” Then
hasilbaru = 0
Else
hasilbaru = CDbl(txtdisplay.Text)
End If
Select Case operator
Case opnol
Hasil = hasilbaru
Case optambah
Hasil = Hasil + hasilbaru
Case opkurang
Hasil = Hasil – hasilbaru
Case opkali
Hasil = Hasil * hasilbaru
Case opbagi

If hasilbaru = 0 Then
MsgBox “tidak bisa dibagi 0”, vbOKOnly + vbCritical, “Kalku ERROR”
Call cmdClear_Click
Else
Hasil = Hasil / hasilbaru
End If
End Select
operator = opnol
nilaibaru = True
txtdisplay.Text = Format$(Hasil)
End Sub

semoga bermanfaat.

Iklan