Calculator dengan Visual Basic


Percobaan membuat Calculator dengan Visual Basic

1. Nama percobaan
- Calculator

2. Objek-objek yang digunakan
- Button
-Text Box

3. Coding
Public Class Form1
    Dim nilai1 As Single
    Dim nilai2 As Single
    Dim proses As String
    Dim hasil As Single


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = TextBox1.Text & "2"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = TextBox1.Text & "1"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = TextBox1.Text & "3"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = TextBox1.Text & "4"
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Text = TextBox1.Text & "5"
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        TextBox1.Text = TextBox1.Text & "6"
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        TextBox1.Text = TextBox1.Text & "7"
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        TextBox1.Text = TextBox1.Text & "8"
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        TextBox1.Text = TextBox1.Text & "9"
    End Sub



    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        TextBox1.Text = TextBox1.Text & "0"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        TextBox1.Text = TextBox1.Text & "."
    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        TextBox1.Clear()
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        nilai1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        proses = "+"
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        nilai1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        proses = "-"
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        nilai1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        proses = "*"
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        nilai1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        proses = "/"
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        nilai2 = Val(TextBox1.Text)
        If proses = "+" Then
            hasil = nilai1 + nilai2
        End If
        nilai2 = Val(TextBox1.Text)
        If proses = "-" Then
            hasil = nilai1 - nilai2
        End If
        nilai2 = Val(TextBox1.Text)
        If proses = "*" Then
            hasil = nilai1 * nilai2
        End If
        nilai2 = Val(TextBox1.Text)
        If proses = "/" Then
            hasil = nilai1 / nilai2
        End If
        TextBox1.Text = hasil
    End Sub
End Class

4.Inilah Hasilnya


Percobaan membuat Calculator dengan Visual Basic
oke terimakasih telah berkunjung, selamat mecoba :)
Blog, Updated at: Saturday, March 26, 2016

Pencarian