TEMA 19: Programa Conversión de Temperaturas
7. Programa: este programa convierte grados Centígrados a grados Fahrenheit y viceversa. Para ello se utiliza un nuevo evento llamado KeyPress. Al escribir un valor y pulsar la tecla Enter se efectúa el cambio.
| OBJETO | PROPIEDAD | VALOR |
| Form1 | Caption | Conversión de Temperaturas |
| LblCentigrado | AutoSize Caption Font |
True Grados Centígrados Negrita, 10 |
| LblFahrenheit | AutoSize Caption Font |
True Grados Fahrenheit Negrita, 10 |
| TxtCentigrado | Text | - |
| Txt Fahrenheit | Text | - |
Private Sub TxtCentigrado_Keypress(KeyAscii As Integer)
Bajate el programa completo haciendo clic en la imagen
Dim GradosFahr As Double
If (KeyAscii = 13) Then 'Al pulsar la tecla Enter realiza la conversión
GradosFahr = Val(TxtCentigrado.Text) * 9 / 5 + 32
TxtFahrenheit.Text = Format(GradosFahr)
End If
End Sub
Private Sub TxtFahrenheit_Keypress(KeyAscii As Integer)
Dim GradosCent As Double
If (KeyAscii = 13) Then 'Al pulsar la tecla Enter realiza la conversión
GradosCent = (Val(TxtFahrenheit.Text) - 32) * 5 / 9
TxtCentigrado.Text = Format(GradosCent)
End If
End Sub![]()