Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 131,790 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,665 people online right now. Registration is fast and FREE... Join Now!




Celsius to Fahrenheits converter

 
Reply to this topicStart new topic

Celsius to Fahrenheits converter, how to convert Celsius to Fahrenheit

tirintintin
post 10 Oct, 2008 - 08:21 PM
Post #1


New D.I.C Head

*
Joined: 10 Oct, 2008
Posts: 5

Hi, I have been trying and trying to convert C to F, but I'm doing something wrong. No error appears but the conversion do not come out correct. Can some one tell me what I'm doing wrong.

CODE

Public Class Form1

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ' Clear Celsius
        txtCelsius.Clear()
        ' Clear Fahrenheits labels
        lblFahrenheit.Text = String.Empty
        ' Return the focus to txtCelsius
        txtCelsius.Focus()



    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        ' Make the convertion
        Dim F As Decimal
        Dim C As Decimal
        Dim isConverted As Boolean
        C = (F - 32) * 5 / 9
        isConverted = Decimal.TryParse(txtCelsius.Text, F)

        lblFahrenheit.Text = C.ToString

    End Sub
End Class


I have a txtCelsius and a lblFahrenheit when I write the # of Celsius to be converted to Fahrenheits this number appears -17.777777777. and it happens with every number I try.
Help please.

** Edit ** code.gif
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 10 Oct, 2008 - 08:41 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,911



Thanked 116 times

Dream Kudos: 8450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


The conversion equation for Celsius to Fahrenheit it

QUOTE

F = C x 1.8 + 32.


Fahrenheit to Celsius

QUOTE

C = (F - 32.) / 1.8


So your conversion is wrong because you've got the wrong equation

vb

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
' Make the convertion
Dim F As Decimal
Dim C As Decimal
Dim isConverted As Boolean
'Fahrenheit to Celsius equation:
' F = C x 1.8 + 32
F = C * 1.8 + 32
isConverted = Decimal.TryParse(txtCelsius.Text, F)

lblFahrenheit.Text = C.ToString

End Sub


Hope that helps smile.gif

EDIT: Moved to VB.NET smile.gif
User is offlineProfile CardPM

Go to the top of the page

tirintintin
post 11 Oct, 2008 - 12:40 AM
Post #3


New D.I.C Head

*
Joined: 10 Oct, 2008
Posts: 5

QUOTE(PsychoCoder @ 10 Oct, 2008 - 09:41 PM) *

The conversion equation for Celsius to Fahrenheit it

QUOTE

F = C x 1.8 + 32.


Fahrenheit to Celsius

QUOTE

C = (F - 32.) / 1.8


So your conversion is wrong because you've got the wrong equation

vb

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
' Make the convertion
Dim F As Decimal
Dim C As Decimal
Dim isConverted As Boolean
'Fahrenheit to Celsius equation:
' F = C x 1.8 + 32
F = C * 1.8 + 32
isConverted = Decimal.TryParse(txtCelsius.Text, F)

lblFahrenheit.Text = C.ToString

End Sub


Hope that helps smile.gif

EDIT: Moved to VB.NET smile.gif



Thanks for your help, with the formula. Unfortunately it did not solved my problem, I think that my problem is in my code.Because I tried both formulas and the program did not run as expected. in my book there is some test data to determine if the application is working properly. look

Celsius Fahrenheits
100 212
0 32
56 132.8

when ever i try to put every of this celcius the result in Fahrenheits is -17.777777. No matter how many celsius I put in, is always -17.777777.

Thanks for your Help I appreciate it a lot. hope you can help me.
User is offlineProfile CardPM

Go to the top of the page

Damage
post 11 Oct, 2008 - 02:44 AM
Post #4


D.I.C Addict

Group Icon
Joined: 5 Jun, 2008
Posts: 728



Thanked 7 times

Dream Kudos: 75
My Contributions


thats cause your not changing C
Your creating these as static variables.

CODE

Dim F As Decimal  
Dim C As Decimal  
C = (F - 32) * 5 / 9


CODE

lblFahrenheit.Text = C.ToString



You need to get the value that the user enters into the text box

CODE

dim f as Decimal
dim c as decimal = textBoxCelsius.text

  F = C * 1.8 + 32

'rest of code


the way you were doing it originally, you were setting the values yourself, thats why the result was never changing
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 04:12PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month