private void Convert_Click(object sender, EventArgs e)
{
switch (conversionType.Value)
{
case "temperature":
{
if (convertValue1)
{
textBox2.Text = "";
try
{
double fahrenheightValue = double.Parse(textBox1.Text);
double celsiusValue = (fahrenheightValue - 32) * (5.0 / 9.0);
textBox2.Text = celsiusValue.ToString("F");
}
catch (Exception)
{
textBlock2.Text = "Error";
}
}
else
{
textBox1.Text = "";
try
{
double celsiusValue = double.Parse(textBox2.Text);
double fahrenheitValue = (celsiusValue * (9.0 / 5.0)) + 32;
textBox1.Text = fahrenheitValue.ToString("F");
}
catch (Exception)
{
textBlock1.Text = "Error";
}
}
}
break;
case "spoons":
{
if (convertValue1)
{
textBox2.Text = "";
try
{
double teaspoons = double.Parse(textBox1.Text);
double tablespoons = teaspoons / 3;
textBox2.Text = tablespoons.ToString("F");
}
catch (Exception)
{
textBlock2.Text = "Error";
}
}
else
{
textBox1.Text = "";
try
{
double tablespoons = double.Parse(textBox2.Text);
double teaspoons = tablespoons * 3;
textBox1.Text = teaspoons.ToString("F");
}
catch (Exception)
{
textBlock1.Text = "Error";
}
}
}
break;
}
this.Focus();
}
答案 0 :(得分:0)
Private Sub Convert_Click(sender As Object, e As EventArgs)
Select Case conversionType.Value
Case "temperature"
If True Then
If convertValue1 Then
textBox2.Text = ""
Try
Dim fahrenheightValue As Double = Double.Parse(textBox1.Text)
Dim celsiusValue As Double = (fahrenheightValue - 32) * (5.0 / 9.0)
textBox2.Text = celsiusValue.ToString("F")
Catch generatedExceptionName As Exception
textBlock2.Text = "Error"
End Try
Else
textBox1.Text = ""
Try
Dim celsiusValue As Double = Double.Parse(textBox2.Text)
Dim fahrenheitValue As Double = (celsiusValue * (9.0 / 5.0)) + 32
textBox1.Text = fahrenheitValue.ToString("F")
Catch generatedExceptionName As Exception
textBlock1.Text = "Error"
End Try
End If
End If
Exit Select
Case "spoons"
If True Then
If convertValue1 Then
textBox2.Text = ""
Try
Dim teaspoons As Double = Double.Parse(textBox1.Text)
Dim tablespoons As Double = teaspoons / 3
textBox2.Text = tablespoons.ToString("F")
Catch generatedExceptionName As Exception
textBlock2.Text = "Error"
End Try
Else
textBox1.Text = ""
Try
Dim tablespoons As Double = Double.Parse(textBox2.Text)
Dim teaspoons As Double = tablespoons * 3
textBox1.Text = teaspoons.ToString("F")
Catch generatedExceptionName As Exception
textBlock1.Text = "Error"
End Try
End If
End If
Exit Select
End Select
Me.Focus()
End Sub
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================