Kamis, 17 Juli 2014
Aplikasi Kalkulator
sebelumnya buat form nya sebagai berikut :
Public Class Form1
Dim operandi1 As Double
Dim [operator] As String
Dim baru As Boolean = True
Dim temp As Double
Dim operand2 As Double
Dim OPH As Boolean = False
Private Property operand1 As Double
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "0"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "0"
End If
End Sub
Private Sub btntambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntambah.Click
If baru = True Then
operandi1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = "+"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operandi1 + Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "+"
ElseIf [operator] = "-" Then
temp = operandi1 - Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "+"
ElseIf [operator] = "x" Then
temp = operandi1 * Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "+"
ElseIf [operator] = ":" Then
temp = operandi1 / Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "+"
End If
End If
baru = False
End Sub
Private Sub btnkurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkurang.Click
If baru = True Then
operandi1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = "-"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operandi1 + Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "-"
ElseIf [operator] = "-" Then
temp = operandi1 - Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "-"
ElseIf [operator] = "x" Then
temp = operandi1 * Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "-"
ElseIf [operator] = ":" Then
temp = operandi1 / Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "-"
End If
End If
baru = False
End Sub
Private Sub btnkali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkali.Click
If baru = True Then
operandi1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = "x"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operandi1 + Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "x"
ElseIf [operator] = "-" Then
temp = operandi1 - Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "x"
ElseIf [operator] = ";" Then
temp = operand1() / Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "x"
ElseIf [operator] = "x" Then
temp = operand1() * Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = "x"
End If
End If
baru = False
End Sub
Private Sub btnbagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbagi.Click
If baru = True Then
operandi1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = ":"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operand1() + Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = ":"
ElseIf [operator] = "-" Then
temp = operand1() - Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = ":"
ElseIf [operator] = "x" Then
temp = operand1() * Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = ":"
ElseIf [operator] = ":" Then
temp = operand1() / Val(TextBox1.Text)
operandi1 = temp
TextBox1.Text = ""
[operator] = ":"
End If
End If
baru = False
End Sub
Private Sub btnsamadengan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsamadengan.Click
Dim hasil As Double
operand2 = Val(TextBox1.Text)
Select Case [operator]
Case "+"
hasil = operandi1 + operand2
TextBox1.Text = hasil.ToString
baru = True
Case "-"
hasil = operandi1 - operand2
TextBox1.Text = hasil.ToString
Case ":"
hasil = operandi1 / operand2
TextBox1.Text = hasil.ToString
Case "x"
hasil = operandi1 * operand2
TextBox1.Text = hasil.ToString
baru = True
End Select
TextBox1.Text = hasil.ToString
End Sub
Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
TextBox1.Text = ""
operandi1 = 0
temp = 0
baru = True
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "1"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "1"
End If
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "2"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "2"
End If
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "3"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "3"
End If
End Sub
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "4"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "4"
End If
End Sub
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "5"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "5"
End If
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "6"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "6"
End If
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "7"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "7"
End If
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "8"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "8"
End If
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
If OPH = True Or TextBox1.Text = "0" Then
TextBox1.Text = "9"
OPH = False
Else
TextBox1.Text = TextBox1.Text + "9"
End If
End Sub
Private Sub btntitik_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntitik.Click
If InStr(TextBox1.Text, ".") > 0 Then
Exit Sub
Else
TextBox1.Text = TextBox1.Text & "."
End If
End Sub
End Class
Langganan:
Posting Komentar (Atom)


Tidak ada komentar:
Posting Komentar