Kalkulator Sederhana: Oleh: Fatahul Arifin

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

Kalkulator Sederhana

Oleh :
Fatahul Arifin
Bentuk Interface Rancangan
Program
 

Dim bil1 As Integer


Dim bil2 As Integer
Dim hasil As Single
Dim operator As Integer '1 - Penjumlahan, 2 - Pengurangan,
3 - Perkalian dan 4 – Pembagian
Private Sub Form_Load()
txtBil1.Text = ""
txtBil2.Text = ""
txtHasil.Text = ""
End Sub
Private Sub optPembagian_Click()
lblOperator.Caption = "/"
operator = 4
End Sub
Private Sub optPengurangan_Click()
lblOperator.Caption = "-"
operator = 2
End Sub

Private Sub optPenjumlahan_Click()


lblOperator.Caption = "+"
operator = 1
End Sub

Private Sub optPerkalian_Click()


lblOperator.Caption = "X"
operator = 3
End Sub
Private Sub cmdHitung_Click()
bil1 = txtBil1.Text
bil2 = txtBil2.Text
If operator = 1 Then
hasil = bil1 + bil2
txtHasil.Text = hasil
ElseIf operator = 2 Then
hasil = bil1 - bil2
txtHasil.Text = hasil
ElseIf operator = 3 Then
hasil = bil1 * bil2
txtHasil.Text = hasil
ElseIf operator = 4 Then
hasil = CSng(bil1) / CSng(bil2)
txtHasil.Text = hasil
Else
MsgBox "Anda belum memilih operator"
End If
End Sub
Private Sub cmdLagi_Click()
Dim jawab As Integer
jawab = MsgBox("Anda ingin mencoba lagi?", vbYesNo)
If jawab = vbYes Then
txtBil1.Text = ""
txtBil2.Text = ""
txtHasil.Text = ""
Else
Unload Me
End If
End Sub

You might also like