Page 1 of 1

Reputation:

# math equation for Temperature converter buttons

Posted 04 May 2010 - 07:03 PM

Hi,
I've pretty much have this assignment done. My main problem is to get the math to pan out and it's making me crazy. It's gotten to the point of staring blankly at my screen for the last 4 hours.
I'm hoping that someone would be willing to take a quick peak and give me a shove in the right direction.
The purpose is to type in a number in a textbox then choose using a fahrenheit radio button and a celsius button to calculate the corresponding conversion in a label box.
Thanks so much if you're able to give me a nudge and hopefully I'm not breaking any rules by asking.

``` Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
Dim dblTemp As Double
Dim dblResult As Double
Convert.ToString(txtTemp)
If radCelsius.Checked = True Then
dblResult = (dblTemp * 9) / 5 - 32
ElseIf radFahrenheit.Checked = True Then
dblResult = (dblTemp * 5 / 9) + 32
End If
lblResult.Text = Format(dblResult, ".")
End Sub
```

This post has been edited by AdamSpeight2008: 04 May 2010 - 11:53 PM
Reason for edit:: Please use the code tags.

Is This A Good Question/Topic? 0

## Replies To: math equation for Temperature converter buttons

### #2 Damage

• Lord of Schwing

Reputation: 299
• Posts: 1,989
• Joined: 05-June 08

## Re: math equation for Temperature converter buttons

Posted 05 May 2010 - 01:48 AM

are you saying your maths is off?
so like they enter in 1 in the textbox and fahrenheit's selected the label should then read 33.8
or if they enter in 1 and celsius is selected the label should read -17.2222222

is that what your after?

Tc = (5/9)*(Tf-32); Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit

Tf = (9/5)*Tc+32; Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit

### #3 Luc001

Reputation: 84
• Posts: 617
• Joined: 04-May 09

## Re: math equation for Temperature converter buttons

Posted 05 May 2010 - 03:02 AM

Hi,

I'm a little confused with th input in your textbox.

Quote

The purpose is to type in a number in a textbox then choose using a fahrenheit radio button and a celsius button to calculate the corresponding conversion in a label box.

What value is that input Celsius, Fahrenheit or Kelvin or something totally different.

Here's an example with the input value in the textbox is in Celsius grades.

```Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

If (radcelsius.Checked = True) Then

If (IsNumeric(enterTemp.Text) = True) Then
lblResult.Text = enterTemp.Text

End If
End If
If (radfahrenheit.Checked = True) Then
If (IsNumeric(enterTemp.Text) = True) Then
lblResult.Text = (Val(enterTemp.Text) * 5/9) + 32

End If
End If

End Sub
```

Reputation:

## Re: math equation for Temperature converter buttons

Posted 05 May 2010 - 05:21 AM

Damage, on 05 May 2010 - 12:48 AM, said:

are you saying your maths is off?
so like they enter in 1 in the textbox and fahrenheit's selected the label should then read 33.8
or if they enter in 1 and celsius is selected the label should read -17.2222222

is that what your after?

Tc = (5/9)*(Tf-32); Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit

Tf = (9/5)*Tc+32; Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit