Sei sulla pagina 1di 5

http://www.recursosdelweb.

com/como-hacer-una-calculadora-en-visual-basic-net-vb/ Public Class Form1 Function buscar(ByVal txtval As String, ByVal car As Char) As Boolean Dim b As Integer For b = 1 To txtval.Length If Convert.ToChar(Mid(txtval, b, 1)) = car Then Return False End If Next Return True End Function Dim val1, val2 As Double Dim banR, ban, ban_br As Integer Dim oper As String Private Sub txt0_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt0.Click If banR = 0 Then r.Text &= "0" Else r.Text = "0" End If End Sub Private Sub txt1_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt1.Click If banR = 0 Then r.Text &= "1" Else r.Text = "1" End If End Sub Private Sub txt2_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt2.Click If banR = 0 Then r.Text &= "2" Else r.Text = "2" End If End Sub Private Sub txt3_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt3.Click If banR = 0 Then r.Text &= "3" Else r.Text = "3" End If End Sub Private Sub txt4_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt4.Click If banR = 0 Then r.Text &= "4" Else r.Text = "4" End If End Sub

Private Sub txt5_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt5.Click If banR = 0 Then r.Text &= "5" Else r.Text = "5" End If End Sub Private Sub txt6_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt6.Click If banR = 0 Then r.Text &= "6" Else r.Text = "6" End If End Sub Private Sub txt7_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt7.Click If banR = 0 Then r.Text &= "7" Else r.Text = "7" End If End Sub Private Sub txt8_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt8.Click If banR = 0 Then r.Text &= "8" Else r.Text = "8" End If End Sub Private Sub txt9_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txt9.Click If banR = 0 Then r.Text &= "9" Else r.Text = "9" End If End Sub Private Sub txtce_Click(ByVal sender As System.Object, ByVal e As System.Eve ntArgs) Handles txtce.Click oper = "" val2 = 0 r.Text = "" banR = 0 ban_br = 0 r.Focus() End Sub Private Sub txtc_Click(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles txtc.Click banR = 0 ban = 0 ban_br = 0

oper = "" val1 = 0 val2 = 0 r.Text = "" r.Focus() End Sub Private Sub txtigual_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles txtigual.Click val2 = Val(r.Text) Select Case oper Case "+" val1 += val2 Case "-" val1 -= val2 Case "*" val1 *= val2 Case "/" val1 /= val2 End Select r.Text = val1 banR = 1 ban = 1 ban_br = 1 End Sub Private Sub txtadd_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles txtadd.Click If ban = 0 Then val1 = Val(r.Text) oper = "+" r.Text = "" r.Focus() ban = 1 Else val2 = Val(r.Text) If ban_br = 1 Then 'si ya presiono el boton de = ban_br = 0 Else Select Case oper Case "+" val1 += val2 Case "-" Case "*" Case "/" End Select End If oper = "+" r.Text = val1 banR = 1 End If End Sub Private Sub txtsub_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles txtsub.Click If ban = 0 Then val1 = Val(r.Text) oper = "-" r.Text = "" r.Focus()

ban = 1 Else val2 = Val(r.Text) If ban_br = 1 Then 'si ya presiono el boton de = ban_br = 0 Else Select Case oper Case "+" val1 += val2 Case "-" Case "*" Case "/" End Select End If oper = "-" r.Text = val1 banR = 1 End If End Sub Private Sub txtmul_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles txtmul.Click If ban = 0 Then val1 = Val(r.Text) oper = "*" r.Text = "" r.Focus() ban = 1 Else val2 = Val(r.Text) If ban_br = 1 Then 'si ya presiono el boton de = ban_br = 0 Else Select Case oper Case "+" val1 += val2 Case "-" Case "*" Case "/" End Select End If oper = "*" r.Text = val1 banR = 1 End If End Sub Private Sub txtdiv_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles txtdiv.Click If ban = 0 Then val1 = Val(r.Text) oper = "/" r.Text = "" r.Focus() ban = 1 Else val2 = Val(r.Text) If ban_br = 1 Then 'si ya presiono el boton de = ban_br = 0 Else

Select Case oper Case "+" val1 += val2 Case "-" Case "*" Case "/" End Select End If oper = "/" r.Text = val1 banR = 1 End If End Sub Private Sub txtpunto_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles txtpunto.Click If buscar(r.Text, ".") = True Then r.Text &= "." End If End Sub End Class - See more at: http://www.recursosdelweb.com/como-hacer-una-calculadora-en-visua l-basic-net-vb/#sthash.oqXMT7y5.dpuf

Potrebbero piacerti anche