Manual de Visual Basic Principiante

 

  Lección: 5

 

Capítulo: Ejercicio 3: Calculadora

 

 

Crea un formulario con cuatro etiquetas, tres cajas de texto, una caja de combo, tres botones y escribe el siguiente código:

 

Private Sub Form_Load()

 

Combo1.AddItem "Dividir"

 

Combo1.AddItem "Multiplicar"

 

Combo1.AddItem "Restar"

 

Combo1.AddItem "Sumar"

 

End Sub

 

El botón Nuevo Cálculo

 

Private Sub Command1_Click()

 

text1 = ""

 

text2 = ""

 

text3 = ""

 

text1.SetFocus

 

End Sub

 

El botón Calcular

 

Private Sub Command2_Click()

 

If Combo1 = "Sumar" Then

 

Text3 = Val(Text1) + Val(Text2)

 

ElseIf Combo1 = "Restar" Then

 

Text3 = Val(Text1) - Val(Text2)

 

ElseIf Combo1 = "Multiplicar" Then

 

Text3 = Val(Text1) * Val(Text2)

 

ElseIf Combo1 = "Dividir" Then

 

Text3 = Val(Text1) / Val(Text2)

 

End If

 

End Sub

 

El botón Salir

 

Private Sub Command3_Click()

 

Unload Me

 

End

 

End Sub

 

   Volver al índice!