Visual Basic - Form cambia de Celtius a Fahrenheit
Written by lopezatienza on 29 Octubre 2008 – 12:50 -Introducimos un TextBox llamado "tbfahrenheit".
Introducimos un Button llamado "btcentigrados".
Introducimos un Button llamado "btfahnrenheit".
Introducimos un Button llamado "btnlimpiar".
Introduciremos el siguiente código a nuestro "Form1.vb" (Añadiremos el código a sus respectivas funciones)
Public Class Form1
Dim centi As Single
Dim fahren As Single
Private Sub btncentigrados_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncentigrados.Click
Try
centi = tbcentigrados.Text
fahren = (centi * 9) / 5 + 32
tbfahrenheit.Text = fahren
Catch ex As Exception
MessageBox.Show("Introduzca un número entero válido", "Error")
End Try
End Sub
Private Sub btnfahrenheit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfahrenheit.Click
Try
fahren = tbfahrenheit.Text
centi = ((fahren - 32) * 5 / 9)
tbcentigrados.Text = centi
Catch ex As Exception
MessageBox.Show("Introduzca un número entero válido", "Error")
End Try
End Sub
Private Sub btnlimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlimpiar.Click
tbcentigrados.Text = ""
tbfahrenheit.Text = ""
End Sub
End Class
Tags: Visual Basic
Posted in Visual Basic .NET |
