• Viernes 19 de Abril de 2024, 11:20

Autor Tema:  [tutorial]calculadora Muy Sencilla En Visual Basic  (Leído 3294 veces)

mycrosystem-ard

  • Nuevo Miembro
  • *
  • Mensajes: 17
    • Ver Perfil
[tutorial]calculadora Muy Sencilla En Visual Basic
« en: Domingo 18 de Mayo de 2008, 15:13 »
0
CREAR UNA CALCULADORA EN
VISUAL BASIC

Lo primero de todo es crear 3 cajas de texto una para cada factor y otra para el resultado de las operaciones, y un botón para cada operación (sumar, restar, dividir y multiplicar) siguientes:

Para sumar: (Este código se introduce en el botón que quieres que sea el de sumar)
Textbox3.Text = Val(Textbox1.Text) + Val(Textbox2.Text)

Para restar: (Este código se introduce en el botón que quieres que sea el de restar)
Textbox3.Text = Val(Textbox1.Text) - Val(Textbox2.Text)

Para dividir: (Este código se introduce en el botón que quieres que sea el de dividir)
Textbox3.Text = Val(Textbox1.Text) / Val(Textbox2.Text)

Para multiplicar: (Este código se introduce en el botón que quieres que sea el de multiplicar)
Textbox3.Text = Val(Textbox1.Text) * Val(Textbox2.Text)

SALUDOS
Tutoriales De Programación & Diseño Gráfico En : http]

anarkia87

  • Nuevo Miembro
  • *
  • Mensajes: 4
    • Ver Perfil
    • http://www.thedaniex.com
Re: [tutorial]calculadora Muy Sencilla En Visual Basic
« Respuesta #1 en: Martes 20 de Mayo de 2008, 01:11 »
0
Vale ai muchas formas de hacer una calculadora bueno aca les dejo n simple ejemplo de una calculadora
1.- Primero creamos un Textbox llamado "visor"
2.- Luego creamos 10 botonoes (ComamdButton) y a cada unos de los botones le ponen de nobre asi n1, n2, n3, n4, n5, n6, n7, n8, n9, n0
3. Luego un boton con el nombre "Limpiar"
4.- y por ultimo 5 botones con los siguientes nombres (suma, resta, division, multiplicacion, igual) y acontinuacion copien este codigo..

Dim opera As Byte
Dim num1, num2, resp As Double

Private Sub divicion_Click()
    num1 = Val(visor.Text)
    opera = 4
    visor.Text = ""
End Sub

Private Sub Form_Load()
    num1 = 0
    num2 = 0
End Sub

Private Sub igual_Click()
    resp = 0
    num2 = Val(visor.Text)
    If opera = 1 Then
        resp = num1 + num2
    End If
        If opera = 2 Then
            resp = Val(num1) - Val(num2)
   
        End If
            If opera = 3 Then
                resp = num1 * num2
            End If
                If opera = 4 Then
                    If num2 = 0 Then
                        MsgBox "No se puede Dividir entre cero"
                Exit Sub
                    End If
                        resp = num1 / num2
                End If
                        visor.Text = resp
End Sub

Private Sub limpiar_Click()
    visor.Text = ""
    num1 = 0
    num2 = 0
    resp = 0
End Sub

Private Sub multiplicacion_Click()
    num1 = Val(visor.Text)
    opera = 3
    visor.Text = ""
End Sub

Private Sub n0_Click()
    visor.Text = visor.Text + Str(0)
End Sub

Private Sub n1_Click()
    visor.Text = visor.Text + Str(1)
End Sub

Private Sub n2_Click()
    visor.Text = visor.Text + Str(2)
End Sub

Private Sub n3_Click()
    visor.Text = visor.Text + Str(3)
End Sub

Private Sub n4_Click()
    visor.Text = visor.Text + Str(4)
End Sub

Private Sub n5_Click()
    visor.Text = visor.Text + Str(5)
End Sub

Private Sub n6_Click()
    visor.Text = visor.Text + Str(6)
End Sub

Private Sub n7_Click()
    visor.Text = visor.Text + Str(7)
End Sub

Private Sub n8_Click()
    visor.Text = visor.Text + Str(8)
End Sub

Private Sub n9_Click()
    visor.Text = visor.Text + Str(9)
End Sub

Private Sub resta_Click()
    num1 = Val(visor.Text)
    opera = 2
    visor.Text = ""
End Sub

Private Sub salir_Click()
    End
End Sub

Private Sub suma_Click()
    num1 = Val(visor.Text)
    opera = 1
    visor.Text = ""
End Sub

Nota: el text aik ponerle en su propiedad Enabled = False
bueno aca tambien les dejo el programa hehco saludos
El mensaje contiene 1 archivo adjunto. Debes ingresar o registrarte para poder verlo y descargarlo.
"Yo solo se que entre mas creo saber mas dudas tengo" Pero eso es lo hermoso del conocimiento "El Aprehender"