jueves, 3 de mayo de 2012

RETO 4 – Operación Aritmética


Public Class Form1
    Private Sub txtb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtb.TextChanged
        If txta.Text <> "" And txtb.Text <> "" Then
            btncalcular.Enabled = True
        Else
            btncalcular.Enabled = False
        End If
    End Sub

    Private Sub txta_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txta.TextChanged
        If txta.Text <> "" And txtb.Text <> "" Then
            btncalcular.Enabled = True
        Else
            btncalcular.Enabled = False
        End If

    End Sub

    Private Sub btncalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalcular.Click
        Dim m, d, s, r As Double
        s = Val(txta.Text) + Val(txtb.Text)
        r = Val(txta.Text) - Val(txtb.Text)
        m = Val(txta.Text) * Val(txtb.Text)
        d = Val(txta.Text) / Val(txtb.Text)
        lstresultado.Items.Clear()
        If chkloperacion.GetItemCheckState(0) = CheckState.Checked Then
            lstresultado.Items.Add(Val(txta.Text) & " + " & Val(txtb.Text) & "  = " & s)
        End If
        If chkloperacion.GetItemCheckState(1) = CheckState.Checked Then
            lstresultado.Items.Add(Val(txta.Text) & " - " & Val(txtb.Text) & "   = " & r)
        End If
        If chkloperacion.GetItemCheckState(2) = CheckState.Checked Then
            lstresultado.Items.Add(Val(txta.Text) & " * " & Val(txtb.Text) & "   = " & m)
        End If
        If chkloperacion.GetItemCheckState(3) = CheckState.Checked Then
            lstresultado.Items.Add(Val(txta.Text) & " / " & Val(txtb.Text) & "   = " & d)
        End If
    End Sub

    Private Sub btnsalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsalir.Click
        Dim salida As Integer = MsgBox("desea salir de verdad?", MsgBoxStyle.YesNo + 32, "Mensaje")
        If salida = 6 Then
            End
        End If
    End Sub

    Private Sub txta_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txta.Validating
        If Not IsNumeric(txta.Text) Then
            Me.epcod.SetError(Me.txta, "Error ingrese dato tipo Numerico")
            Me.txta.Focus()
        Else
            Me.epcod.SetError(Me.txta, "")
        End If
    End Sub

    Private Sub txtb_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtb.Validating
        If Not IsNumeric(txtb.Text) Then
            Me.epcod.SetError(Me.txtb, "Error ingrese dato tipo Numerico")
            Me.txtb.Focus()
        Else
            Me.epcod.SetError(Me.txtb, "")
        End If
    End Sub
End Class

1 comentario:

  1. GRACIAS POR TU APORTE, BUSCABA EJERCICIOS PARA PRACTICAR, HAY EN OTROS LADOS, PERO LOS TUYOS SON LOS MEJORES. ME GUSTAN PORQUE TIENEN LOS FORMULARIOS INCLUIDOS.
    no se como agregarme a tu blog, mi correo es jsb_carlos@hotmail.com

    ResponderEliminar