Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: glas en 14 Octubre 2010, 05:01 AM

Título: Calculadora simple [VB]
Publicado por: glas en 14 Octubre 2010, 05:01 AM
Hola migos, hace dos dias comence con esto de visual basic la verdad me parece un lenguaje muy bueno para aplicaciones graficas, estoy usando visual studio k es realmente completo y facil de usar, empeze a hacer una simple calculadora, bueno aki esta el codigo del algoritmo de calculos no el de los graficos..bueno amigos espero cualkier comentario que me ayude a aprender mas..saludos ::)

link del .exe: http://www.megaupload.com/?d=G5WU7VAJ (http://www.megaupload.com/?d=G5WU7VAJ)


Código (vb) [Seleccionar]

Public Class Ventana
    Dim Valor1 As Double, Result As Double, Valor2 As Double, Marca_Suma As Boolean
    Dim Marca_Resta As Boolean, Marca_Multiplicacion As Boolean, Marca_Division As Boolean
   
    Private Sub Uno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Uno.Click
        Valor1 = Valor1 * 10 + 1
        Pantalla.Text = Valor1
    End Sub

    Private Sub Dos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dos.Click
        Valor1 = Valor1 * 10 + 2
        Pantalla.Text = Valor1
    End Sub

    Private Sub Tres_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tres.Click
        Valor1 = Valor1 * 10 + 3
        Pantalla.Text = Valor1
    End Sub

    Private Sub Cuatro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cuatro.Click
        Valor1 = Valor1 * 10 + 4
        Pantalla.Text = Valor1
    End Sub

    Private Sub Cinco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cinco.Click
        Valor1 = Valor1 * 10 + 5
        Pantalla.Text = Valor1
    End Sub

    Private Sub Seis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seis.Click
        Valor1 = Valor1 * 10 + 6
        Pantalla.Text = Valor1
    End Sub

    Private Sub Siete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Siete.Click
        Valor1 = Valor1 * 10 + 7
        Pantalla.Text = Valor1
    End Sub

    Private Sub Ocho_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ocho.Click
        Valor1 = Valor1 * 10 + 8
        Pantalla.Text = Valor1
    End Sub

    Private Sub Nueve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nueve.Click
        Valor1 = Valor1 * 10 + 9
        Pantalla.Text = Valor1
    End Sub

    Private Sub Cero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cero.Click
        Valor1 = Valor1 * 10
        Pantalla.Text = Valor1
    End Sub

    Private Sub Resta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Resta.Click
        Pantalla.Text = "-"
        Valor2 = Valor1
        Valor1 = 0
        Marca_Resta = True
    End Sub

    Private Sub Suma_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Suma.Click
        Pantalla.Text = "+"
        Valor2 = Valor1
        Valor1 = 0
        Marca_Suma = True
    End Sub

    Private Sub Dividir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dividir.Click
        Pantalla.Text = "/"
        Valor2 = Valor1
        Valor1 = 0
        Marca_Division = True
    End Sub

    Private Sub Multiplicar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Multiplicar.Click
        Pantalla.Text = "x"
        Valor2 = Valor1
        Valor1 = 0
        Marca_Multiplicacion = True
    End Sub

    Private Sub Resultado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Resultado.Click
        If Marca_Suma = True Then
            Result = Valor2 + Valor1
        ElseIf Marca_Resta = True Then
            Result = Valor2 - Valor1
        ElseIf Marca_Multiplicacion = True Then
            Result = Valor2 * Valor1
        ElseIf Marca_Division = True Then
            Result = Valor2 / Valor1
        End If
        Pantalla.Text = Result
    End Sub

    Private Sub Limpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Limpiar.Click
        Pantalla.Text = "" : Valor1 = 0 : Valor2 = 0
        Marca_Division = False : Marca_Multiplicacion = False : Marca_Resta = False : Marca_Suma = False
    End Sub
End Class
Título: Re: Calculadora simple [VB]
Publicado por: BlackZeroX en 14 Octubre 2010, 06:23 AM
esto va en .NET

y si no me equivoco puede simplificar las operaciones Aritmeticas de la siguiente forma

Código (Vbnet) [Seleccionar]


Valor1 = Valor1 * 10 + 9



por

Código (Vbnet) [Seleccionar]


Valor1 *= 10 + 9



aun que

Código (vbnet) [Seleccionar]


       Valor1 = Valor1 * 10 + 9
       Pantalla.Text = Valor1



quedaria mejor asi

Código (vbnet) [Seleccionar]


       Pantalla.Text = Valor1 * 10 + 9



Nota: Es una desgracia que ya no existe de forma NATIVA los arreglos de controles... ahora se tienen que hacer Magia Negra y Malavares para poderlo hacer de nuevo asi ¬¬".

Dulce Infierno Lunar!¡.