Tema: FAQ's de VB6
Ver Mensaje Individual
  #152 (permalink)  
Antiguo 23/07/2006, 21:29
Avatar de Dark Wolf
Dark Wolf
 
Fecha de Ingreso: julio-2006
Ubicación: En Uruguay
Mensajes: 32
Antigüedad: 17 años, 9 meses
Puntos: 0
Hola, ¿que tal?, les traigo mi tercer manual, esta vez veremos como desarrollar nuestra propia calculadora en Visual Basic.

Veamos:

Vamos a necesitar un solo form con: 16 Commands Buttons de 375x375.
Dos label sin texto escondidas y un TextBox.



Luego viene el código, que esta vez será bastante largo, es exactamente asi:

Cita:
Option Explicit

Private Sub Command1_Click()
On Error Resume Next
If Label1.Caption = "+" Then
Text1.Text = Val(Label2.Caption) + Text1.Text
End If

If Label1.Caption = "-" Then
Text1.Text = Val(Label2.Caption) - Text1.Text
End If

If Label1.Caption = "*" Then
Text1.Text = Val(Label2.Caption) * Text1.Text
End If

If Label1.Caption = "/" Then
Text1.Text = Val(Label2.Caption) / Text1.Text
End If

End Sub

Private Sub Command10_Click()
Text1.Text = Text1.Text + "9"
End Sub

Private Sub Command11_Click()
Text1.Text = Text1.Text + "8"
End Sub

Private Sub Command12_Click()
Text1.Text = Text1.Text + "7"
End Sub

Private Sub Command13_Click()
Text1.Text = Text1.Text + "6"
End Sub

Private Sub Command14_Click()
Text1.Text = Text1.Text + "5"
End Sub

Private Sub Command15_Click()
Text1.Text = Text1.Text + "0"
End Sub

Private Sub Command16_Click()
Text1.Text = ""
Label2.Caption = ""
End Sub

Private Sub Command2_Click()
Text1.Text = Text1.Text + "4"
End Sub

Private Sub Command3_Click()
On Error Resume Next
Label1.Caption = ""
Label1.Caption = "+"
Label2.Caption = Text1.Text
Text1.Text = ""
End Sub

Private Sub Command4_Click()
On Error Resume Next
Label1.Caption = ""
Label1.Caption = "-"
Label2.Caption = Text1.Text
Text1.Text = ""
End Sub

Private Sub Command5_Click()
On Error Resume Next
Label1.Caption = ""
Label1.Caption = "*"
Label2.Caption = Text1.Text
Text1.Text = ""
End Sub

Private Sub Command6_Click()
On Error Resume Next
Label1.Caption = ""
Label1.Caption = "/"
Label2.Caption = Text1.Text
Text1.Text = ""
End Sub

Private Sub Command7_Click()
Text1.Text = Text1.Text + "3"
End Sub

Private Sub Command8_Click()
Text1.Text = Text1.Text + "2"
End Sub

Private Sub Command9_Click()
Text1.Text = Text1.Text + "1"
End Sub

Private Sub Form_Load()

End Sub








Bien, la explicacion del codigo es sencilla, es muy larga porque debemos asignarle un evento a los 16 botones, los eventos son insertar texto segun el boton que apretemos, llamar a el ordenador para que realice el calculo y rellenar nuevamente el text box con el resultado mediante las labels que tendremos sin texto y vacias, aunque es largo no es complejo ni dificil de entender.

Con eso la aplicacion ya estara lista, es bastante sencilla, hice el manual para tocar un poco el tema de aplicaciones con muchos objetos y largos trozos de código.
Descargen el codigo fuente de este manual aquí


Saludos