The document contains code for a calculator program written in Visual Basic. It defines event handler subroutines for buttons that perform number entry, arithmetic operations, equals, clear, and plus/minus functions. The subroutines update the TextBox1 field with button clicks and perform calculations when the equals button is clicked by storing interim values and operation symbols in variables.
The document contains code for a calculator program written in Visual Basic. It defines event handler subroutines for buttons that perform number entry, arithmetic operations, equals, clear, and plus/minus functions. The subroutines update the TextBox1 field with button clicks and perform calculations when the equals button is clicked by storing interim values and operation symbols in variables.
The document contains code for a calculator program written in Visual Basic. It defines event handler subroutines for buttons that perform number entry, arithmetic operations, equals, clear, and plus/minus functions. The subroutines update the TextBox1 field with button clicks and perform calculations when the equals button is clicked by storing interim values and operation symbols in variables.
The document contains code for a calculator program written in Visual Basic. It defines event handler subroutines for buttons that perform number entry, arithmetic operations, equals, clear, and plus/minus functions. The subroutines update the TextBox1 field with button clicks and perform calculations when the equals button is clicked by storing interim values and operation symbols in variables.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 3
Nama : Hari Rahmad Perdana
Nim : 03021181722014 Kelas : B (indralaya)
Public Class Form1
Dim Bilangan1, Bilangan2 As Single Dim Simbol As String
Private Sub Angka1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka1.Click TextBox1.Text = TextBox1.Text + Angka1.Text End Sub
Private Sub Angka2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka2.Click TextBox1.Text = TextBox1.Text + Angka2.Text End Sub
Private Sub Angka3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka3.Click TextBox1.Text = TextBox1.Text + Angka3.Text End Sub
Private Sub Angka4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka4.Click TextBox1.Text = TextBox1.Text + Angka4.Text End Sub
Private Sub Angka5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka5.Click TextBox1.Text = TextBox1.Text + Angka5.Text End Sub
Private Sub Angka6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka6.Click TextBox1.Text = TextBox1.Text + Angka6.Text End Sub
Private Sub Angka7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka7.Click TextBox1.Text = TextBox1.Text + Angka7.Text End Sub
Private Sub Angka8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka8.Click TextBox1.Text = TextBox1.Text + Angka8.Text End Sub
Private Sub Angka9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka9.Click TextBox1.Text = TextBox1.Text + Angka9.Text End Sub
Private Sub Angka0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Angka0.Click If TextBox1.Text = "" Then TextBox1.Text = "" Else TextBox1.Text = TextBox1.Text + Angka0.Text End If End Sub
Private Sub Bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Bersih.Click TextBox1.Text = "" End Sub
Private Sub Tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Tambah.Click If TextBox1.Text = "" Then Exit Sub Bilangan1 = CSng(TextBox1.Text) Simbol = "+" TextBox1.Clear() End Sub
Private Sub Kurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Kurang.Click If TextBox1.Text = "" Then Exit Sub Bilangan1 = CSng(TextBox1.Text) Simbol = "-" TextBox1.Clear() End Sub
Private Sub Bagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Bagi.Click If TextBox1.Text = "" Then Exit Sub Bilangan1 = CSng(TextBox1.Text) Simbol = "/" TextBox1.Clear() End Sub
Private Sub Kali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Kali.Click If TextBox1.Text = "" Then Exit Sub Bilangan1 = CSng(TextBox1.Text) Simbol = "*" TextBox1.Clear() End Sub
Private Sub Hasil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Hasil.Click Dim hasil As Single Bilangan2 = CSng(TextBox1.Text) Select Case Simbol Case "+" hasil = Bilangan1 + Bilangan2 Case "-" hasil = Bilangan1 - Bilangan2 Case "/" hasil = Bilangan1 / Bilangan2 Case "*" hasil = Bilangan1 * Bilangan2 End Select TextBox1.Text = hasil End Sub
Private Sub PlusMinus_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PlusMinus.Click If TextBox1.Text = "" Then Exit Sub If Val(TextBox1.Text) > 0 Then TextBox1.Text = Val(TextBox1.Text) * -1 Else TextBox1.Text = Val(TextBox1.Text) * -1 End If End Sub
Private Sub Koma_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Koma.Click TextBox1.Text = TextBox1.Text + Koma.Text End Sub End Class