zavier19
Usuario (República Dominicana)
Les hice algunas mejoras al codigo . Y funciona mejor ya mas adelamte publicare mas.. Estara mejor mas adelante Public Class Form1 Public Class Form1 Dim num1 As Double Dim num2 As Double Dim op, op2 As String Dim num, memory As Double Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN0.Click 'Cero' If TextBox1.Text = "0" Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "0" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN1.Click 'Uno' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "1" Punto.Enabled = True End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN2.Click 'Dos' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "2" Punto.Enabled = True End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN3.Click 'Tres' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "3" Punto.Enabled = True End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN4.Click 'Cuatro' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "4" Punto.Enabled = True End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN5.Click 'Cinco' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "5" Punto.Enabled = True End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN6.Click 'Seis' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "6" Punto.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN7.Click 'Siete' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "7" Punto.Enabled = True End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN8.Click 'Ocho' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "8" Punto.Enabled = True End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN9.Click 'Nueve' If TextBox1.Text = 0 Then TextBox1.Text = "" End If TextBox1.Text = TextBox1.Text & "9" Punto.Enabled = True End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CE.Click 'CE' TextBox1.Clear() TextBox1.Text = 0 End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C.Click 'C' BTN1.Enabled = True BTN7.Enabled = True TextBox1.Text = 0 Punto.Enabled = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MC.Click 'MC' If TextBox1.Text = "" Then TextBox1.Text = 0 Punto.Enabled = True Else memory = 0 TextBox1.Text = "0" Punto.Enabled = True Label1.ForeColor = System.Drawing.Color.White End If End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MR.Click 'MR' If TextBox1.Text = "" Then TextBox1.Text = 0 Punto.Enabled = True Else TextBox1.Text = memory Punto.Enabled = True Label1.ForeColor = System.Drawing.Color.Black End If End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MS.Click 'MS' If TextBox1.Text = "" Then TextBox1.Text = 0 Punto.Enabled = True Else memory = TextBox1.Text TextBox1.Text = memory End If Punto.Enabled = True Label1.ForeColor = System.Drawing.Color.Black End Sub Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M1.Click 'M+' memory = memory + Val(TextBox1.Text) Punto.Enabled = True Label1.ForeColor = System.Drawing.Color.Black End Sub Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M2.Click 'M-' If TextBox1.Text = "" Then TextBox1.Text = 0 Punto.Enabled = True Else memory = memory - Val(TextBox1.Text) Punto.Enabled = True Label1.ForeColor = System.Drawing.Color.Black End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backspace.Click 'Backspace' If TextBox1.Text = "0" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "1" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "2" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "3" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "4" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "5" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "6" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "7" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "8" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "9" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-1" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-2" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-3" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-4" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-5" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-6" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-7" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-8" Then TextBox1.Text = 0 ElseIf TextBox1.Text = "-9" Then TextBox1.Text = 0 Else TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1) End If Punto.Enabled = True End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Punto.Click 'Punto' TextBox1.Text = TextBox1.Text & "." op2 = 1 If op2 = "1" Then Punto.Enabled = True End If End Sub Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mas.Click 'Mas' num1 = Val(TextBox1.Text) TextBox1.Text = "" op = "+" If TextBox1.Text = "1" Then ElseIf TextBox1.Text = "2" Then ElseIf TextBox1.Text = "3" Then ElseIf TextBox1.Text = "4" Then ElseIf TextBox1.Text = "5" Then ElseIf TextBox1.Text = "6" Then ElseIf TextBox1.Text = "7" Then ElseIf TextBox1.Text = "8" Then ElseIf TextBox1.Text = "9" Then Else : TextBox1.Text = "0" End If Punto.Enabled = True End Sub Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menos.Click 'Menos' num1 = Val(TextBox1.Text) TextBox1.Text = "" op = "-" If TextBox1.Text = "1" Then ElseIf TextBox1.Text = "2" Then ElseIf TextBox1.Text = "3" Then ElseIf TextBox1.Text = "4" Then ElseIf TextBox1.Text = "5" Then ElseIf TextBox1.Text = "6" Then ElseIf TextBox1.Text = "7" Then ElseIf TextBox1.Text = "8" Then ElseIf TextBox1.Text = "9" Then Else : TextBox1.Text = "0" End If Punto.Enabled = True End Sub Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Multiplicacion.Click 'Multiplicacion' num1 = Val(TextBox1.Text) TextBox1.Text = "" op = "*" If TextBox1.Text = "1" Then ElseIf TextBox1.Text = "2" Then ElseIf TextBox1.Text = "3" Then ElseIf TextBox1.Text = "4" Then ElseIf TextBox1.Text = "5" Then ElseIf TextBox1.Text = "6" Then ElseIf TextBox1.Text = "7" Then ElseIf TextBox1.Text = "8" Then ElseIf TextBox1.Text = "9" Then Else : TextBox1.Text = "0" End If Punto.Enabled = True End Sub Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Division.Click 'Division' num1 = Val(TextBox1.Text) TextBox1.Text = "" op = "/" If TextBox1.Text = "1" Then ElseIf TextBox1.Text = "2" Then ElseIf TextBox1.Text = "3" Then ElseIf TextBox1.Text = "4" Then ElseIf TextBox1.Text = "5" Then ElseIf TextBox1.Text = "6" Then ElseIf TextBox1.Text = "7" Then ElseIf TextBox1.Text = "8" Then ElseIf TextBox1.Text = "9" Then Else : TextBox1.Text = "0" End If Punto.Enabled = True End Sub Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles masmenos.Click 'MasMenos' TextBox1.Text = TextBox1.Text * -1 Punto.Enabled = True End Sub Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles raiz.Click 'Raiz' If TextBox1.Text < 0 Then TextBox1.Text = "Entrada no Valida" Else TextBox1.Text = System.Math.Sqrt(TextBox1.Text) Punto.Enabled = True End If End Sub Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Porciento.Click 'Porciento' TextBox1.Text = TextBox1.Text / 100 End Sub Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles X.Click '1/x' If TextBox1.Text = 0 Then TextBox1.Text = "No se puede dividir entre cero" Else TextBox1.Text = 1 / TextBox1.Text Punto.Enabled = True End If End Sub Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Igual.Click 'Igual' num2 = Val(TextBox1.Text) If (num1 = 0) Then Else If (op = "+" Then TextBox1.Text = num1 + num2 End If If (op = "-" Then TextBox1.Text = num1 - num2 End If If (op = "*" Then TextBox1.Text = num1 * num2 End If If (op = "/" Then If num2 = 0 Then TextBox1.Text = "No se puede dividir entre cero" Else TextBox1.Text = num1 / num2 End If End If If (op = "1/x" Then TextBox1.Text = 1 / num1 End If End If Punto.Enabled = True End Sub End Class