Sei sulla pagina 1di 4

E2 VB 8

Public Class Form1 'Holds which operation to perform. Dim operand1 As Decimal 'Holds which operation to perform. Dim operand2 As Decimal Dim ope As Char Dim isOpe As Boolean 'Holds whether the remaining values in the 'textbox is the calculated values or not. Dim calculated As Boolean = False Dim memoryRecall As Decimal Dim memorysave As Decimal Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click, Button3.Click, Button2.Click, Button18.Click, Button17.Click, Button16.Click, Button12.Click, Button11.Click, Button10.Click, Button1.Click If isOpe = True Then txtDisplay.Clear() isOpe = False End If txtDisplay.Text &= CType(sender, Button).Text End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click, Button7.Click, Button6.Click, Button15.Click, Button14.Click, Button19.Click isOpe = True ope = CType(sender, Button).Text operand1 = txtDisplay.Text End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click 'First make sure memory contains something to calculate. If txtDisplay.Text = Nothing OrElse txtDisplay.Text = "" Then Exit Sub operand2 = txtDisplay.Text If ope = "+" Then 'adding first operand to 2nd operand. txtDisplay.Text = CDec(operand1) + CDec(operand2) End If If ope = "-" Then

txtDisplay.Text = CDec(operand1) - CDec(operand2) End If If ope = "*" Then txtDisplay.Text = CDec(operand1) * CDec(operand2) End If If ope = "/" Then txtDisplay.Text = CDec(operand1) / CDec(operand2) End If 'hmm. my % value is fixed at 100%, haha If ope = "%" Then txtDisplay.Text = CDec(txtDisplay.Text) / CDec(100) * operand1 End If 'getting the square root of the nubmers If ope = "" Then txtDisplay.Text = Math.Sqrt(operand2) End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click txtDisplay.Clear() End Sub Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click txtDisplay = Nothing End Sub Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click txtDisplay.Paste() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

If txtDisplay.Text.Contains(".") Then Exit Sub Else txtDisplay.AppendText(".") End If End Sub Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click End Sub Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click 'These codes will convert a Signed number to a Unsigned number and vice-versa. Dim txtValue As Decimal 'txtValue decimal variable created above. If Decimal.TryParse(txtDisplay.Text, txtValue) Then 'If "-1" is returned then its a negative number. If it returns 1, then its a positive 'number If Math.Sign(txtValue) = "-1" Then ' to convert a value to a positive number :) txtDisplay.Text = Math.Abs(txtValue) 'math.absolute value.= getting the real numbers in short 'only positive integers will be accepted Else ' to convert a value to a negative number :) txtDisplay.Text = -txtDisplay.Text End If End If End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click 'decimal tryparse , to overload but specify the invalid value. If Decimal.TryParse(txtDisplay.Text, vbNullString) Then txtDisplay.Text = 1 / (CDec(txtDisplay.Text)) 'Update to True since you should have just calculated the values. calculated = True

End If End Sub Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click txtDisplay.Text = Nothing End Sub Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click End Sub Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click End Sub Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click 'Keep removing digits one at a time until there are no more left. ' If txtDisplay.TextLength = 0 Then Exit Sub Else 'removing digits by 1 starting from right. txtDisplay.Text = txtDisplay.Text.Remove(txtDisplay.TextLength - 1) End If End Sub End Class

Potrebbero piacerti anche