Lunes, Agosto 22, 2011

Dim converting As Boolean = False
Dim fmt As String = "n1"

Private Sub TextBox1_TextChanged(sender As System.Object, _
e As System.EventArgs) Handles TextBox1.TextChanged
'Celsius text
If converting Then Exit Sub
converting = True
Dim c, f As Double
If Double.TryParse(TextBox1.Text.Replace(",", ""), c) Then
f = c * (9 / 5) + 32
TextBox2.Text = f.ToString(fmt)
Label1.Text = ""
Else
Label1.Text = "Invalid input"
TextBox2.Text = "Error"
End If
converting = False
End Sub

Private Sub TextBox2_TextChanged(sender As System.Object, _
e As System.EventArgs) Handles TextBox2.TextChanged
'Fahrenheit
If converting Then Exit Sub
converting = True
Dim c, f As Double
If Double.TryParse(TextBox2.Text.Replace(",", ""), f) Then
c = (f - 32) * (5 / 9)
TextBox1.Text = c.ToString(fmt)
Label1.Text = ""
Else
Label1.Text = "Invalid input"
TextBox1.Text = "Error"
End If
converting = False
End Sub

Walang komento:

Mag-post ng isang Komento