Jumat, 30 November 2012

TUTORIAL PROGRAM KALKULATOR modul 2


ANALISIS LISTING

Option Explicit On
Public Class Form1
    Dim FirstNumber As Single
    Dim SecondNumber As Single
    Dim AnswerNumber As Single
    Dim ArithmeticProcess As String

(SINGLE TIPE NUMERIC SEDANGKAN STRING ALFANUMERIC)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label2.Text = Label2.Text & "1"
    End Sub
(MEMBERI ANGKA 1)
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label2.Text = Label2.Text & "2"
    End Sub
(MEMBERI ANGKA 2)

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

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

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

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

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

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

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

    Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click
        Label2.Text = Label2.Text & "0"
    End Sub
(MEMBERI ANGKA 0)

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Label2.Text = Label2.Text & "."
    End Sub
(MEMBERI TANDA TITIK UNTUK PENGGANTI KOMA)

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Label1.Text = ""
        Label2.Text = ""
    End Sub

(menghapus angka yang sudah diisi ditabel yang disediakan)

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = Label2.Text & " +"
        Label2.Text = ""
        ArithmeticProcess = "+"
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA PENJUMLAHAN)

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = Label2.Text & " -"
        Label2.Text = ""
        ArithmeticProcess = "-"
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA PENGURANGAN)

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = Label2.Text & " x"
        Label2.Text = ""
        ArithmeticProcess = "x"
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA PERKALIAN)

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = Label2.Text & " /"
        Label2.Text = ""
        ArithmeticProcess = "/"
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA PEMBAGIAN)

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = Label2.Text & " ^"
        Label2.Text = ""
        ArithmeticProcess = "^"
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA KUADRATKAN)

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = "√ " & Label2.Text
        Label2.Text = FirstNumber ^ (1 / 2)
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA PENGAKARAN)

    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        FirstNumber = Val(Label2.Text)
        Label1.Text = Label2.Text & " log10"
        Label2.Text = Math.Log10(FirstNumber)
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA LOG 10)

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        Label1.Text = "sin " & Label2.Text
        Label2.Text = Math.Sin(Label2.Text * (22 / 7 / 180))
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA SINUS)

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        Label1.Text = "cos " & Label2.Text
        Label2.Text = Math.Cos(Label2.Text * (22 / 7 / 180))
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA COSINUS)

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        Label1.Text = "tan " & Label2.Text
        Label2.Text = Math.Tan(Label2.Text * (22 / 7 / 180))
    End Sub
(MENGHITUNG ANGKA-ANGKA DENGAN PROSES MATEMATIKA TANGEN)

(untuk membuat program perhitungan didalam kalkulator seperti +, -, *, sin, cos, dll)
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        SecondNumber = Val(Label2.Text)
        If ArithmeticProcess = "+" Then
            AnswerNumber = FirstNumber + SecondNumber
            Label2.Text = AnswerNumber
            Label1.Text = Label1.Text & " " & SecondNumber & " ="
        End If
(JAWABAN DARI PROSES PENJUMLAHAN)

        If ArithmeticProcess = "-" Then
            AnswerNumber = FirstNumber - SecondNumber
            Label2.Text = AnswerNumber
            Label1.Text = Label1.Text & " " & SecondNumber & " ="
        End If

(JAWABAN DARI PROSES PENGURANGAN)

        If ArithmeticProcess = "x" Then
            AnswerNumber = FirstNumber * SecondNumber
            Label2.Text = AnswerNumber
            Label1.Text = Label1.Text & " " & SecondNumber & " ="
        End If

(JAWABAN DARI PROSES PERKALIAN)

        If ArithmeticProcess = "^" Then
            AnswerNumber = FirstNumber ^ SecondNumber
            Label2.Text = AnswerNumber
            Label1.Text = Label1.Text & " " & SecondNumber & " ="
        End If

(JAWABAN DARI PROSES KUADRATAN)

        If ArithmeticProcess = "/" Then
            If SecondNumber = "0" Then
                MsgBox("cannot devide by zero", 0, "warning")
                Label1.Text = ""
                Exit Sub

(JAWABAN DARI PROSES PEMBAGIAN)

            End If
            AnswerNumber = FirstNumber / SecondNumber
            Label1.Text = Label1.Text & " " & SecondNumber & " ="
        End If
        Label2.Text = AnswerNumber
    End Sub

(perintah untuk menjawab perhitungan yang sudah diisi ditabel yang tersedia)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button20.Enabled = False
        Button16.Enabled = False
        Button10.Enabled = False
        Button8.Enabled = False
        Button7.Enabled = False
        Button13.Enabled = False
        Button19.Enabled = False
        Button9.Enabled = False
        Button12.Enabled = False
        Button11.Enabled = False
        Button4.Enabled = False
        Button18.Enabled = False
        Button22.Enabled = False
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button5.Enabled = False
        Button13.Enabled = False
        Button21.Enabled = False
        Button14.Enabled = False
        Button17.Enabled = False
        Button6.Enabled = False
        Button15.Enabled = False
        Button0.Enabled = False
        Button25.Enabled = False
        BackColor = Color.Aquamarine

(memulai program kalkulator dan memberi warna pada background)

    End Sub

    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        Button20.Enabled = True
        Button0.Enabled = True
        Button16.Enabled = True
        Button10.Enabled = True
        Button8.Enabled = True
        Button7.Enabled = True
        Button13.Enabled = True
        Button19.Enabled = True
        Button25.Enabled = True
        Button9.Enabled = True
        Button12.Enabled = True
        Button11.Enabled = True
        Button4.Enabled = True
        Button18.Enabled = True
        Button22.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button5.Enabled = True
        Button13.Enabled = True
        Button21.Enabled = True
        Button14.Enabled = True
        Button17.Enabled = True
        Button6.Enabled = True
        Button15.Enabled = True
    End Sub

(menghidupkan tombol-tombol yang ada di program tersebut)

    Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
        Button20.Enabled = False
        Button0.Enabled = False
        Button16.Enabled = False
        Button10.Enabled = False
        Button8.Enabled = False
        Button7.Enabled = False
        Button13.Enabled = False
        Button19.Enabled = False
        Button25.Enabled = False
        Button9.Enabled = False
        Button12.Enabled = False
        Button11.Enabled = False
        Button4.Enabled = False
        Button18.Enabled = False
        Button22.Enabled = False
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button5.Enabled = False
        Button13.Enabled = False
        Button21.Enabled = False
        Button14.Enabled = False
        Button17.Enabled = False
        Button6.Enabled = False
        Button15.Enabled = False
        Label1.Text = ""
        Label2.Text = ""
    End Sub

(mematikan tombol-tombol yang ada di program tersebut)

    Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        If Label1.Text.Length <> 0 Then
            Label1.Text = Label1.Text.Remove(Label1.Text.Length - 1)
        End If
    End Sub
End Class

(menghapus angka satu persatu yang ada pada tabel tersebut)
TUTORIAL PROGRAM KALKULATOR
 
KOMPONEN TOOLBOX:
KOMPONEN
PROPERTIES
KETERANGAN
FORM 1
NAME
TEXT
FORM1
KALKULATOR
TEXTBOX
NAME
TEXT
TEXTALIGN
LABEL 1

KIRI ATAS
TEXTBOX
NAME
TEXT
TEXTALIGN
LABEL 2

KANAN BAWAH
BUTTON 1
NAME
TEXT
BUTTON1
1
BUTTON 2
NAME
TEXT
BUTTON2
2
BUTTON 3
NAME
TEXT
BUTTON3
3
BUTTON 4
NAME
TEXT
BUTTON4
4
BUTTON 5
NAME
TEXT
BUTTON5
5
BUTTON 6
NAME
TEXT
BUTTON6
6
BUTTON 7
NAME
TEXT
BUTTON7
7
BUTTON 8
NAME
TEXT
BUTTON8
8
BUTTON 9
NAME
TEXT
BUTTON9
9
BUTTON 0
NAME
TEXT
BUTTON0
0
BUTTON 10
NAME
TEXT
BUTTON10
.
BUTTON 12
NAME
TEXT
BUTTON 12
RESET
BUTTON 13
NAME
TEXT
BUTTON 13
+
BUTTON 14
NAME
TEXT
BUTTON 14
-
BUTTON 15
NAME
TEXT
BUTTON 15
X
BUTTON 16
NAME
TEXT
BUTTON 12
/
BUTTON 17
NAME
TEXT
BUTTON 17
SIN
BUTTON 18
NAME
TEXT
BUTTON 18
COS
BUTTON 19
NAME
TEXT
BUTTON 19
TAN
BUTTON 20
NAME
TEXT
BUTTON 20
^
BUTTON 21
NAME
TEXT
BUTTON 21
BUTTON 22
NAME
TEXT
BUTTON 22
LOG 10
BUTTON 23
NAME
TEXT
BUTTON 23
ON
BUTTON 24
NAME
TEXT
BUTTON 24
OFF
BUTTON 25
NAME
TEXT
BUTTON 25
C
BUTTON 11
NAME
TEXT
BUTTON 11
=

Tidak ada komentar:

Posting Komentar