MEMBUAT CALCULATOR DI VISUAL STUDIO 2013


1. Design
 
2. Listing Program
Public Class Form1
    Dim Operand1 As Double
    Dim Operand2 As Double
    Dim [Operator] As String
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button11.Click
        TextBox1.Text = TextBox1.Text & sender.text



    End Sub

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        TextBox1.Text = ""

    End Sub

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        If InStr(TextBox1.Text, ".") > 0 Then
            Exit Sub
        Else
            TextBox1.Text = TextBox1.Text & "."
        End If
    End Sub

    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        Operand1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        TextBox1.Focus()
        [Operator] = "+"

    End Sub

    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        Operand1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        TextBox1.Focus()
        [Operator] = "-"

    End Sub

    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        Operand1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        TextBox1.Focus()
        [Operator] = "*"

    End Sub

    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
        Operand1 = Val(TextBox1.Text)
        TextBox1.Text = ""
        TextBox1.Focus()
        [Operator] = "/"

    End Sub

    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        Dim convert As Single
        If TextBox1.Text <> 0 Then
            convert = 1 / Val(TextBox1.Text)
            TextBox1.Text = convert

        End If
    End Sub

    Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
        TextBox1.Text = -1 * TextBox1.Text

    End Sub

    Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
        Dim Result As Double
        Operand2 = Val(TextBox1.Text)

        ' If [Operator] = "+" Then
        Result = Operand1 + Operand2
        'ElseIf [Operator] = "-" Then
        Result = Operand1 - Operand2
        ' ElseIf [Operator] = "/" Then
        Result = Operand1 / Operand2
        ' ElseIf [Operator] = "*" Then
        Result = Operand1 * Operand2
        ' End If

        Select Case [Operator]
            Case "+"
                Result = Operand1 + Operand2
                MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
                TextBox1.Text = Result.ToString("#,###.00")

            Case "-"
                Result = Operand1 - Operand2
                MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
                TextBox1.Text = Result.ToString("#,###.00")

            Case "/"
                Result = Operand1 / Operand2
                MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
                TextBox1.Text = Result.ToString("#,###.00")

            Case "*"
                Result = Operand1 * Operand2
                MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
                TextBox1.Text = Result.ToString("#,###.00")


        End Select
        TextBox1.Text = Result.ToString("#,###.00")

    End Sub
End Class
 


Jika ada yang kurang paham bisa comen atau di di sini( fb saya)

Subscribe to receive free email updates:

0 Response to " MEMBUAT CALCULATOR DI VISUAL STUDIO 2013"

Post a Comment