MEMBUAT KALKULATOR DENGAN VB.NET
listing program
Public Class Form1
Dim operand1 As Double
Dim [operator] As String
Dim baru As Boolean = True
Dim temp As Double
Dim operand2 As Double
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn2.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btntmbh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntmbh.Click
If baru = True Then
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = "+"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operand1 + Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "+"
ElseIf [operator] = "-" Then
temp = operand1 - Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "+"
ElseIf [operator] = "x" Then
temp = operand1 * Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "+"
ElseIf [operator] = ":" Then
temp = operand1 / Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "+"
End If
End If
baru = False
End Sub
Private Sub btnkrg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkrg.Click
If baru = True Then
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = "-"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operand1 + Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "-"
ElseIf [operator] = "-" Then
temp = operand1 - Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "-"
ElseIf [operator] = "x" Then
temp = operand1 * Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "-"
ElseIf [operator] = ":" Then
temp = operand1 / Val(TextBox1.Text)
operand1 = 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
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = "x"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operand1 + Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "x"
ElseIf [operator] = "-" Then
temp = operand1 - Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "x"
ElseIf [operator] = ";" Then
temp = operand1 / Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = "x"
ElseIf [operator] = "x" Then
temp = operand1 * Val(TextBox1.Text)
operand1 = 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
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
[operator] = ":"
ElseIf baru = False Then
If [operator] = "+" Then
temp = operand1 + Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = ":"
ElseIf [operator] = "-" Then
temp = operand1 - Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = ":"
ElseIf [operator] = "x" Then
temp = operand1 * Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = ":"
ElseIf [operator] = ":" Then
temp = operand1 / Val(TextBox1.Text)
operand1 = temp
TextBox1.Text = ""
[operator] = ":"
End If
End If
baru = False
End Sub
Private Sub btnhasil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhasil.Click
Dim hasil As Double
operand2 = Val(TextBox1.Text)
Select Case [operator]
Case "+"
hasil = operand1 + operand2
TextBox1.Text = hasil.ToString
baru = True
Case "-"
hasil = operand1 - operand2
TextBox1.Text = hasil.ToString
Case ":"
hasil = operand1 / operand2
TextBox1.Text = hasil.ToString
Case "x"
hasil = operand1 * operand2
TextBox1.Text = hasil.ToString
baru = True
End Select
TextBox1.Text = hasil.ToString
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
Private Sub btnclr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclr.Click
TextBox1.Text = ""
operand1 = 0
temp = 0
baru = True
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, Btn1.Click, Btn2.Click, btn3.Click, btn4.Click, Btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click
TextBox1.Text = TextBox1.Text & sender.text
End Sub
End Class
Komentar
Posting Komentar