Monday, 2 January 2017

Membuat Kalkulator menggunakan VB.Net

Hallo Sobat Coder, pada kesempatan kali ini kita akan membuat Kalkulator menggunakan VB.Net. Saya menggunakan Visual Studio 2013 Coumunity. 

Baik langsung saja design form seperti dibawah ini :
Komponen yang dibutuhkan antara lain:

Button = 16
TextBox = 1

Let's Coding..
Masukan Codingan seperti dibawah ini pada Public Class Form1:

    Public value_1 As Double
    Public value_2 As Double
    Public result As Double
    Public equal As String


Sebelum namespace masukan juga script seperti dibawah ini :
Imports System.Diagnostics
Imports System.Security.Principal
Lalu Pada Button silahkan copas Coding Berikut :

    Private Sub buttonPlus_Click(sender As Object, e As EventArgs) Handles buttonPlus.Click
        value_1 = Double.Parse(textBox1.Text)
        textBox1.Text = ""
        equal = "+"
    End Sub

    Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        textBox1.Text = textBox1.Text + button1.Text
    End Sub

    Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
        textBox1.Text = textBox1.Text + button2.Text
    End Sub

    Private Sub button3_Click(sender As Object, e As EventArgs) Handles button3.Click
        textBox1.Text = textBox1.Text + button3.Text
    End Sub

    Private Sub button4_Click(sender As Object, e As EventArgs) Handles button4.Click
        textBox1.Text = textBox1.Text + button4.Text
    End Sub

    Private Sub button5_Click(sender As Object, e As EventArgs) Handles button5.Click
        textBox1.Text = textBox1.Text + button5.Text
    End Sub

    Private Sub button6_Click(sender As Object, e As EventArgs) Handles button6.Click
        textBox1.Text = textBox1.Text + button6.Text
    End Sub

    Private Sub button7_Click(sender As Object, e As EventArgs) Handles button7.Click
        textBox1.Text = textBox1.Text + button7.Text
    End Sub

    Private Sub button8_Click(sender As Object, e As EventArgs) Handles button8.Click
        textBox1.Text = textBox1.Text + button8.Text
    End Sub

    Private Sub button9_Click(sender As Object, e As EventArgs) Handles button9.Click
        textBox1.Text = textBox1.Text + button9.Text
    End Sub

    Private Sub button10_Click(sender As Object, e As EventArgs) Handles button10.Click
        textBox1.Text = textBox1.Text + button10.Text
    End Sub

    Private Sub buttonMinuse_Click(sender As Object, e As EventArgs) Handles buttonMinuse.Click
        value_1 = Double.Parse(textBox1.Text)
        textBox1.Text = ""
        equal = "-"
    End Sub

    Private Sub buttonMultiple_Click(sender As Object, e As EventArgs) Handles buttonMultiple.Click
        value_1 = Double.Parse(textBox1.Text)
        textBox1.Text = ""
        equal = "*"
    End Sub

    Private Sub buttonDivide_Click(sender As Object, e As EventArgs) Handles buttonDivide.Click
        value_1 = Double.Parse(textBox1.Text)
        textBox1.Text = ""
        equal = "/"
    End Sub

    Private Sub buttonEqual_Click(sender As Object, e As EventArgs) Handles buttonEqual.Click
        Select Case equal
            Case ("+")
                value_2 = Double.Parse(textBox1.Text)
                result = value_1 + value_2
                textBox1.Text = result.ToString()
                Exit Select

            Case ("-")
                value_2 = Double.Parse(textBox1.Text)
                result = value_1 - value_2
                textBox1.Text = result.ToString()
                Exit Select

            Case ("*")
                value_2 = Double.Parse(textBox1.Text)
                result = value_1 * value_2
                textBox1.Text = result.ToString()
                Exit Select

            Case ("/")
                value_2 = Double.Parse(textBox1.Text)
                result = value_1 / value_2
                textBox1.Text = result.ToString()
                Exit Select
        End Select
    End Sub

    Private Sub buttonClear_Click(sender As Object, e As EventArgs) Handles buttonClear.Click
        textBox1.Text = ""
    End Sub


Codingan diatas saya sudah rubah penamaan Button terlebih dahulu..
Lalu jalankan program sobat Coder dan test. Maka terlihat seperti gambar berikut :
Semoga bermanfaat, Tetap bereksplorasi, semangat dan tentunya Coding Dong! ;)

Selamat berjumpa pada tutorial berikutnya :) 

2 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete