Wednesday, 11 December 2013

Cara Coding Kalkulator Ilmiah di VB

Jika kita Googling pastinya kita akan menemukan banyak aplikasi Kalkulator Ilmiah baik yang berbayar ataupun yang gratisan, tapi apa salahnya kita mencoba membuat sendiri aplikasi ini.
Aplikasi ini saya buat menggunakan Visual Basic 6.0…..
Ok….Langsung kita ke TKP……

1.

Buka VB kamu dan buat project baru, dan lanjutkan membuat disain aplikasi kalkukator seperti pada gambar di bawah.
clip_image002
 

2.

Atur Properti masing-masing fungsi seperti tabel berikut :
Komponen
Properti
TextBox1 Name : Text1 ; Text : 0.
Command1 Name : Angka ; Caption : 0
Command2 Name : Angka ; Caption : 1
Command3 Name : Angka ; Caption : 2
Command4 Name : Angka ; Caption : 3
Command5 Name : Angka ; Caption : 4
Command6 Name : Angka ; Caption : 5
Command7 Name : Angka ; Caption : 6
Command8 Name : Angka ; Caption : 7
Command9 Name : Angka ; Caption : 8
Command10 Name : Angka ; Caption : 9
Command11 Name : Koma ; Caption : . (titik)
Command12 Name : C ; Caption : C
Command13 Name : CE ; Caption : CE
Command14 Name : Operator ; Caption : +
Command15 Name : Operator ; Caption : -
Command16 Name : Operator ; Caption : x
Command17 Name : Operator ; Caption : /
Command18 Name : Operator ; Caption : =
Command19 Name : Persen ; Caption : %
Command20 Name : Pi ; Caption : Pi
Command21 Name : Sinus ; Caption : Sinus
Command22 Name : Cosinus ; Caption : Cos
Command23 Name : Tangen ; Caption : Tgn
Command24 Name : Kubik ; Caption : X3
Command25 Name : Kuadrat ; Caption : X2
Command26 Name : Akar ; Caption : Sqr
Command27 Name : Operator ; Caption : Mod

3.
untuk source codenya silahkan copas source code berikut :
Option Explicit
Dim Operator1, Operator2 As Double
Dim duodecimal As Integer
Dim interoperates As Integer
Dim ultimate
Dim operation
Dim temptext1
Private Sub Akar_Click()
Text1 = Sqr(Text1)
End Sub
Private Sub Angka_Click(Index As Integer)
    If ultimate <> "angka" Then
        Text1 = Format(0, ".")
        duodecimal = False
    End If
    If duodecimal Then
        Text1 = Text1 + Angka(Index).Caption
    Else
        Text1 = Left(Text1, InStr(Text1, Format(0, ".")) - 1) + Angka(Index).Caption + Format(0, ".")
    End If
    If ultimate = "negative" Then Text1 = "-" & Text1
    ultimate = "angka"
End Sub
Private Sub C_Click()
Text1 = Format(0, "0.")
    Operator1 = 0
    Operator2 = 0
End Sub
Private Sub CE_Click()
Text1 = Format(0, "0.")
    duodecimal = False
    ultimate = "CE"
End Sub
Private Sub Cosinus_Click()
Dim rad2
rad2 = Text1 * (3.14059265358979 / 180)
Text1 = Sin(rad2)
End Sub
Private Sub Form_Load()
    duodecimal = False
    interoperates = 0
    ultimate = ""
    operation = " "
    Text1 = Format(0, "0.")
End Sub
Private Sub Koma_Click()
    If ultimate = "negative" Then
        Text1 = Format(0, "-0.")
    ElseIf ultimate <> "angka" Then
        Text1 = Format(0, "0.")
    End If
    duodecimal = True
    ultimate = "angka"
End Sub
Private Sub Kuadrat_Click()
Text1 = Text1 ^ 2
End Sub
Private Sub Kubik_Click()
Text1 = Text1 ^ 3
End Sub
Private Sub mnTentang_Click()
frmTtg.Show
frmKal.Enabled = False
End Sub
Private Sub mnTutup_Click()
End
End Sub
Private Sub Operator_Click(Index As Integer)
    temptext1 = Text1
    If ultimate = "angka" Then
        interoperates = interoperates + 1
    End If
    Select Case interoperates
        Case 0
        If Operator(Index).Caption = "-" And ultimate <> "negative" Then
            Text1 = "-" & Text1
            ultimate = "negative"
        End If
        Case 1
        Operator1 = Text1
        If Operator(Index).Caption = "-" And ultimate <> "angka" And operation <> "=" Then
            Text1 = "-"
            ultimate = "negative"
        End If
        Case 2
        Operator2 = temptext1
        Select Case operation
            Case "+"
                Operator1 = CDbl(Operator1) + CDbl(Operator2)
            Case "-"
                Operator1 = CDbl(Operator1) - CDbl(Operator2)
            Case "X"
                Operator1 = CDbl(Operator1) * CDbl(Operator2)
            Case "/"
                If Operator2 = 0 Then
                   MsgBox "Tidak Bisa Dibagi Dengan Nol", 48, "Calculator"
                Else
                   Operator1 = CDbl(Operator1) / CDbl(Operator2)
                End If
            Case "="
                Operator1 = CDbl(Operator2)
            Case "%"
                Operator1 = CDbl(Operator1) * CDbl(Operator2)
            Case "Mod"
                Operator1 = CDbl(Operator1) Mod CDbl(Operator2)
            End Select
        Text1 = Operator1
        interoperates = 1
    End Select
    If ultimate <> "negative" Then
        ultimate = "operation"
        operation = Operator(Index).Caption
    End If
End Sub
Private Sub Persen_Click()
    Text1 = Text1 / 100
    ultimate = "operation"
    operation = "%"
    interoperates = interoperates + 1
    duodecimal = True
End Sub
Private Sub Pi_Click()
Dim Pi
Pi = 4 * Atn(1)
Text1 = Pi
End Sub
Private Sub Sinus_Click()
Dim rad
rad = Text1 * (3.14059265358979 / 180)
Text1 = Sin(rad)
End Sub
Private Sub Tangen_Click()
Dim rad3
rad3 = Text1 * (3.14059265358979 / 180)
Text1 = Sin(rad3)
End Sub


O…ya, jika kamu membutuhkan aplikasi beserta source codenya silahkan download disini.

1 comments: