Option Explicit On
Imports VB = Microsoft.VisualBasic
Public Class Form1
Private number1 As Double
Private number2 As Double
Private input As Boolean
Private calfun As String
Private demical As String
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar >= "0" And e.KeyChar <= "9" Then
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
If input = False Then
display.Text += B1.Text
Else
display.Text = B1.Text
input = False
End If
End Sub
Private Sub B2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B2.Click
If input = False Then
display.Text += B2.Text
Else
display.Text = B2.Text
input = False
End If
End Sub
Private Sub B3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B3.Click
If input = False Then
display.Text += B3.Text
Else
display.Text = B3.Text
input = False
End If
End Sub
Private Sub B4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4.Click
If input = False Then
display.Text += B4.Text
Else
display.Text = B4.Text
input = False
End If
End Sub
Private Sub B5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B5.Click
If input = False Then
display.Text += B5.Text
Else
display.Text = B5.Text
input = False
End If
End Sub
Private Sub B6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B6.Click
If input = False Then
display.Text += B6.Text
Else
display.Text = B6.Text
input = False
End If
End Sub
Private Sub B7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B7.Click
If input = False Then
display.Text += B7.Text
Else
display.Text = B7.Text
input = False
End If
End Sub
Private Sub B8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B8.Click
If input = False Then
display.Text += B8.Text
Else
display.Text = B8.Text
input = False
End If
End Sub
Private Sub B9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B9.Click
If input = False Then
display.Text += B9.Text
Else
display.Text = B9.Text
input = False
End If
End Sub
Private Sub B0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B0.Click
If input = False Then
If display.Text.Length >= 1 Then
display.Text += B0.Text
End If
End If
End Sub
Private Sub dot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dot.Click
If display.Text = "" Then
display.Text = "0."
Else
demical = IIf(InStr(display.Text, ".") > 0, "", ".")
display.Text = display.Text & demical
If VB.Left(display.Text, 1) = "0" Then
display.Text = Mid(display.Text, 2)
End If
End If
If display.Text = "." Then display.Text = "0."
End Sub
Private Sub clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click
display.Text = String.Empty
number1 = 0
number2 = 0
calfun = String.Empty
demical = False
End Sub
Private Sub plus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plus.Click
If display.Text.Length <> 0 Then
If calfun = String.Empty Then
number1 = CDbl(display.Text)
display.Text = String.Empty
Else
CalculateTotals()
End If
calfun = "plus"
demical = False
End If
End Sub
Private Sub minus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles minus.Click
If display.Text.Length <> 0 Then
If calfun = String.Empty Then
number1 = CDbl(display.Text)
display.Text = String.Empty
Else
CalculateTotals()
End If
calfun = "minus"
demical = False
End If
End Sub
Private Sub times_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles times.Click
If display.Text.Length <> 0 Then
If calfun = String.Empty Then
number1 = CDbl(display.Text)
display.Text = String.Empty
Else
CalculateTotals()
End If
calfun = "times"
demical = False
End If
End Sub
Private Sub devide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles devide.Click
If display.Text.Length <> 0 Then
If calfun = String.Empty Then
number1 = CDbl(display.Text)
display.Text = String.Empty
Else
CalculateTotals()
End If
calfun = "devide"
demical = False
End If
End Sub
Private Sub equal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equal.Click
If display.Text.Length <> 0 AndAlso number1 <> 0 Then
CalculateTotals()
calfun = ""
demical = False
End If
End Sub
Private Sub CalculateTotals()
number2 = CDbl(display.Text)
Select Case calfun
Case "plus"
number1 = number1 + number2
Case "minus"
number1 = number1 - number2
Case "times"
number1 = number1 * number2
Case "devide"
number1 = number1 / number2
End Select
display.Text = CStr(number1)
input = True
End Sub
End Class
Here is my code. Hope u have clue to let me know where should i edit, add or change.