miércoles, 12 de noviembre de 2008

CREACION DE LA CALCULADORA 2

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

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

End Sub

Private Sub Command1_Click()
num1 = Val(visor.Text)
resp = 9 / 5 * num1 + 32
visor.Text = resp

End Sub

Private Sub Command2_Click()
num1 = Val(visor.Text)
resp = 5 / 9 * (num1 - 32)
visor.Text = resp

End Sub

Private Sub Command3_Click()
num1 = Val(visor.Text)
resp = num1 + 273
visor.Text = resp

End Sub

Private Sub Command4_Click()
num1 = Val(visor.Text)
resp = num1 - 273
visor.Text = resp

End Sub

Private Sub Command5_Click()
num1 = Val(visor.Text)
resp = 5 / 9 * (num1 - 32) + 273
visor.Text = resp

End Sub

Private Sub Command6_Click()
num1 = Val(visor.Text)
resp = 9 / 5 * (num1 - 273) + 32
visor.Text = resp

End Sub

Private Sub Command7_Click()

resp = Val(visor.Text) * -1
visor.Text = resp

End Sub

Private Sub Command8_Click()
num1 = Val(visor.Text)
If num1 < 0 Then
Exit Sub
Else
num1 = Sqr(num1)
End If
visor.Text = num1
End Sub


Private Sub cuadrado_Click()
num1 = Val(visor.Text)
resp = num1 * num1
visor.Text = resp

End Sub

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

End Sub

Private Sub divent_Click()
num1 = Val(visor.Text)
opera = 5
visor.Text = " "

End Sub

Private Sub Form_Load()

num1 = 0
num2 = 0
visor.ShowWhatsThis
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 = num1 - num2
End If

If opera = 3 Then
resp = num1 * num2
End If

If opera = 4 Then
If num2 = 0 Then
MsgBox "Error...No se puede dividir en cero"
Exit Sub
End If

resp = num1 / num2
End If


If opera = 5 Then
If num2 = 0 Then
MsgBox "Error...No se puede dividir en cero"
Exit Sub
End If
resp = num1 \ num2
End If

If opera = 6 Then
If num2 = 0 Then
MsgBox "Error...No se puede dividir en cero"
Exit Sub
End If
resp = num1 Mod num2
End If

If opera = 7 Then
If num2 = 0 Then
MsgBox "Error...No se puede dividir en cero"
Exit Sub
End If
resp = num1 * num2 / 100
End If
visor.Text = resp
End Sub

Private Sub modulo_Click()
num1 = Val(visor.Text)
opera = 6
visor.Text = " "

End Sub

Private Sub mult_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 porciento9_Click()
num1 = Val(visor.Text)
opera = 7
visor.Text = " "

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

Private Sub visor_KeyPress(KeyAscii As Integer)
If KeyAscii <> 57 Then
KeyAscii = 0
End If
End Sub

No hay comentarios: