Вы находитесь на странице: 1из 3

USO DE IF-THEN-ELSE

Problema: Escribir un programa en Visual Basic, en la que se ingresa un valor a convertir y se


escoge una de las unidades (oC o oF) para convertir luego a las 4 unidades de temperatura que
se muestra ms abajo. El formulario propuesto es que sigue. Puede usted variar si lo desea.

EL PROGRAMA.

Public Class Form1

Dim op As Integer

Dim C As Single

Dim F As Single

Dim K As Single

Dim R As Single

----------------------------------------------------------------------------------------------------------------------

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton1.CheckedChanged

op = 1
End Sub

----------------------------------------------------------------------------------------------------------------------

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton2.CheckedChanged

op = 2

End Sub

----------------------------------------------------------------------------------------------------------------------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click

If op = 1 Then

C = Val(TextBox1.Text)

TextBox2.Text = C

F = 9 / 5 * (C) + 32

TextBox3.Text = F

K = 273.15 + C

TextBox4.Text = K

R = 460 + F

TextBox5.Text = R

End If

If op = 2 Then

F = Val(TextBox1.Text)

C = 5 / 9 * (F - 32)

TextBox2.Text = C

TextBox3.Text = F

K = 273.15 + C

TextBox4.Text = K

R = 460 + F

TextBox5.Text = R

End If

End Sub

----------------------------------------------------------------------------------------------------------------------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

TextBox5.Text = ""

End Sub

----------------------------------------------------------------------------------------------------------------------

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click

End

End Sub

----------------------------------------------------------------------------------------------------------------------

End Class

----------------------------------------------------------------------------------------------------------------------

Вам также может понравиться