I'm posting my entire code but its just the last three events towards the bottom. I don't know if they are coded right, if they work, how they work, etc. Corrections or help please?
Public Class Calculator Private variable1 As Double Private variable2 As Double Private tmpValue As Double Private hasDecimal As Boolean Private inputStatus As Boolean Private clearText As Boolean Private calcFunc As String Private memory As Double Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click If inputStatus Then If txtDisplay.Text.Length >= 0 Then txtDisplay.Text += btn0.Text End If End If End Sub Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click If inputStatus Then txtDisplay.Text += btn1.Text Else txtDisplay.Text = btn1.Text inputStatus = True End If End Sub Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click If inputStatus Then txtDisplay.Text += btn2.Text Else txtDisplay.Text = btn2.Text inputStatus = True End If End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click If inputStatus Then txtDisplay.Text += btn3.Text Else txtDisplay.Text = btn3.Text inputStatus = True End If End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click If inputStatus Then txtDisplay.Text += btn4.Text Else txtDisplay.Text = btn4.Text inputStatus = True End If End Sub Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click If inputStatus Then txtDisplay.Text += btn5.Text Else txtDisplay.Text = btn5.Text inputStatus = True End If End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click If inputStatus Then txtDisplay.Text += btn6.Text Else txtDisplay.Text = btn6.Text inputStatus = True End If End Sub Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click If inputStatus Then txtDisplay.Text += btn7.Text Else txtDisplay.Text = btn7.Text inputStatus = True End If End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click If inputStatus Then txtDisplay.Text += btn8.Text Else txtDisplay.Text = btn8.Text inputStatus = True End If End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click If inputStatus Then txtDisplay.Text += btn9.Text Else txtDisplay.Text = btn9.Text inputStatus = True End If End Sub Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click If inputStatus Then If Not hasDecimal Then If txtDisplay.Text.Length > 0 Then If Not txtDisplay.Text = "0" Then txtDisplay.Text += btnDot.Text hasDecimal = True End If Else txtDisplay.Text = "0." End If End If End If End Sub Private Sub CalculateTotals() variable2 = CType(txtDisplay.Text, Double) Select Case calcFunc Case "Add" variable1 = variable1 + variable2 Case "Subtract" variable1 = variable1 - variable2 Case "Divide" variable1 = variable1 / variable2 Case "Multiply" variable1 = variable1 * variable2 End Select txtDisplay.Text = CType(variable1, String) inputStatus = False End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If txtDisplay.Text.Length <> 0 Then If calcFunc = String.Empty Then variable1 = CType(txtDisplay.Text, Double) txtDisplay.Text = String.Empty Else CalculateTotals() End If calcFunc = "Add" hasDecimal = False End If End Sub Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click If txtDisplay.Text.Length <> 0 Then If calcFunc = String.Empty Then variable1 = CType(txtDisplay.Text, Double) txtDisplay.Text = String.Empty Else CalculateTotals() End If calcFunc = "Subtract" hasDecimal = False End If End Sub Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click If txtDisplay.Text.Length <> 0 Then If calcFunc = String.Empty Then variable1 = CType(txtDisplay.Text, Double) txtDisplay.Text = String.Empty Else CalculateTotals() End If calcFunc = "Divide" hasDecimal = False End If End Sub Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click If txtDisplay.Text.Length <> 0 Then If calcFunc = String.Empty Then variable1 = CType(txtDisplay.Text, Double) txtDisplay.Text = String.Empty Else CalculateTotals() End If calcFunc = "Multiply" hasDecimal = False End If End Sub Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click If txtDisplay.Text.Length <> 0 AndAlso variable1 <> 0 Then CalculateTotals() calcFunc = String.Empty hasDecimal = False End If End Sub Private Sub btnBackspace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackspace.Click Dim str As String Dim loc As Integer If txtDisplay.Text.Length > 0 Then str = txtDisplay.Text.Chars(txtDisplay.Text.Length - 1) If str = "." Then hasDecimal = False End If loc = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Remove(loc - 1, 1) End If End Sub Private Sub btnClearEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearEntry.Click txtDisplay.Text = String.Empty hasDecimal = False End Sub Private Sub btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAll.Click txtDisplay.Text = String.Empty variable1 = 0 variable2 = 0 calcFunc = String.Empty hasDecimal = False End Sub Private Sub btnPlusMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlusMinus.Click If inputStatus Then If txtDisplay.Text = -txtDisplay.Text Then txtDisplay.Text = +txtDisplay.Text ElseIf txtDisplay.Text = +txtDisplay.Text Then txtDisplay.Text = -txtDisplay.Text End If End If End Sub Private Sub btnSqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSqrt.Click If txtDisplay.Text.Length <> 0 Then tmpValue = CDbl(txtDisplay.Text) tmpValue = System.Math.Sqrt(tmpValue) txtDisplay.Text = CStr(tmpValue) hasDecimal = False End If End Sub Private Sub btnInverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInverse.Click If txtDisplay.Text.Length <> 0 Then tmpValue = CDbl(txtDisplay.Text) tmpValue = 1 / tmpValue txtDisplay.Text = CStr(tmpValue) hasDecimal = False End If End Sub Private Sub btnMemoryRecall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMemoryRecall.Click If txtbox1.Text = "M" Then txtDisplay.Text = CStr(Memory) inputStatus = True End If End Sub Private Sub btnMemoryPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMemoryPlus.Click If txtDisplay.Text.Length > 0 Then memory = memory + CDbl(txtDisplay.Text) txtbox1.Text = "M" End If End Sub Private Sub btnMemoryClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMemoryClear.Click If txtDisplay.Text.Length > 0 Then memory = memory - CDbl(txtDisplay.Text) txtbox1.Text = "M" End If End Sub Private Sub btnMemoryStore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMemoryStore.Click If inputStatus() = True Then memory = CDbl(txtDisplay.Text) If memory <> 0 Then txtbox1.Text = "M" Else txtbox1.Text = Nothing End If End Sub End Class
This post has been edited by jennxoxo: 13 April 2009 - 06:39 PM

New Topic/Question
Reply



MultiQuote





|