Membuat Kalkulator Serba Guna dengan VB

Dengan bahasa pemrograman VB, kita juga bisa membuat kalkulator dengan cara input data sesuai yg di inginkan ..
--> tampilan form nya :

Tuliskan Coding nya dengan cara mengklick button di Form :

Public Class Form1
    Dim operasi As String
    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        operasi = "+"
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        operasi = "-"
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        operasi = "\"
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        operasi = "^"
    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        operasi = "\"
    End Sub

    Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
        operasi = "*"
    End Sub

    Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged
        operasi = "mod"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BM.Click
        Select Case operasi
            Case "*"
                HM.Text = Val(OM1.Text) * Val(OM2.Text)
            Case "/"
                HM.Text = Val(OM1.Text) / Val(OM2.Text)
            Case "\"
                HM.Text = Val(OM1.Text) \ Val(OM2.Text)
            Case "^"
                HM.Text = Val(OM1.Text) ^ Val(OM2.Text)
            Case "+"
                HM.Text = Val(OM1.Text) + Val(OM2.Text)
            Case "-"
                HM.Text = Val(OM1.Text) - Val(OM2.Text)
            Case "mod"
                HM.Text = Val(OM1.Text) Mod Val(OM2.Text)
        End Select
    End Sub
    Private Sub BF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BF.Click
        HF.Text = Factorial(F.Text)
    End Sub
    Function Factorial(ByVal n As Integer) As Long
        If n = 0 Then
            Factorial = 1
        Else
            Factorial = Factorial(n - 1) * n
        End If
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OPL.Items.Clear()
        OPL.Items.Add("And")
        OPL.Items.Add("Or")
        OPL.Items.Add("Xor")
        OPL.Items.Add("AndAlso")
        OPL.Items.Add("OrElse")

        CL1.Items.Clear()
        CL1.Items.Add("True")
        CL1.Items.Add("False")

        CL2.Items.Clear()
        CL2.Items.Add("True")
        CL2.Items.Add("False")
    End Sub


    Private Sub BL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BL.Click
        Select Case OPL.Text
            Case "And"
                HL.Text = (CBool(CL1.Text) And CBool(CL2.Text)).ToString
            Case "Or"
                HL.Text = (CBool(CL1.Text) Or CBool(CL2.Text)).ToString
            Case "Xor"
                HL.Text = (CBool(CL1.Text) Xor CBool(CL2.Text)).ToString
            Case "AndAlso"
                HL.Text = (CBool(CL1.Text) AndAlso CBool(CL2.Text)).ToString
            Case "OrElse"
                HL.Text = (CBool(CL1.Text) OrElse CBool(CL2.Text)).ToString
        End Select
    End Sub

    Private Sub bni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bni.Click
        Dim i As Integer = 1
        Dim j As Integer = 1
        Dim t As Integer
        Dim iCtr As Integer = 0
        lni.Items.Clear()
        lni.Items.Add(i)
        lni.Items.Add(j)
        For iCtr = 0 To Val(ni.Text)
            t = i
            i += j
            j = t
            lni.Items.Add(i)
        Next
    End Sub
End Class
Selamat Mencoba :)

Comments