Full Version: Celcius to Fahrenheit converter
mraetrudeaujr
I want to make a simple 'form' where the user can enter their "Celcius" number and convert it to 'Fahrenheit' and vice versa. Does anyone here have the code or way to do this?
R. Hicks

CODE
[color="green"]' Converts temperature from Fahrenheit to Celcius/Centigrade[/color]
ublic Function FahrenheitToCelsius(TempF)

FahrenheitToCelsius = (TempF - 32) * 5 / 9

End Function
[color="green"]' Converts temperature from Celcius/Centigrade to Fahrenheit[/color]
Public Function CelsiusToFahrenheit(TempC)

CelsiusToFahrenheit = 32 + TempC * 9 / 5

End Function

RDH
Alan_G
Hi
The formula is
((Cent * 9)/5) + 32
so in whatever event you want to trigger it from, or the Control Source of your txtFar control you'd use something like
Me.txtFar = Round(((Me.txtCent * 9)/5) + 32 , 2)
Change the control names to suit your own.........
HTH
Alan
dannyseager
Here you go..
retty simple
mraetrudeaujr
Hey thanks to all of you guys! I went ahead and used the attached db with the form from Danny Seager. Now I'll modify parts of it to make it more "eye" friendly for my wife and daughter. I already knew the actual calculation, I just didn't think it out enough to use the 'text output' for the results. What I enjoyed the most was seeing the code that would work, and then seeing Danny's simple database with the form. It all made sense then!
Thanks again everybody.
Al Trudeau
dannyseager
mraetrudeaujr
After playing around with it 'cosmetically', I discovered that I didn't need the decimal places. I tried to set the decimal places to "0" (zero) on both controls, but it didn't work. What do I need to get the end result to round up or down to the nearest whole number?
Alan_G
Hi
You could use the Int() function, which will return just the integer part of the calculation unless you need to be precise to round up or down depending on the fractional part of the result...........
HTH
Alan
mraetrudeaujr
Okay. But how (or where) do I insert this into the code?
mraetrudeaujr
I tried to plug in the "Round" function to the code that Danny gave me, but I couldn't get it to work. I thought that all I would have to do was add
ound (
to the first part of the code, and close with another parenthesis after the "Fahrenheit" and "Celcius" portions of the code.
It seems as though this "Round" function would work, if I knew how to use it properly...
Al Trudeau
mraetrudeaujr
I cannot find anything about the "Round" function that could apply here. Every example uses a "Dim" statement to set up the code. So how can I get this "Round" function to apply here?
l Trudeau
Alan_G
Round() will do what it says - round your answer to a set number of decimal places........
e.txtFar = Round(((Me.txtCent * 9)/5) + 32 , 2)
will round to 2 decimal places (eg 98.45)
Int() will just return the integer part........
Me.txtFar = Int(((Me.txtCent * 9)/5) + 32)
will return 98
HTH
Alan
Alan_G
So in Danny's example, to use Round it would look like this
e.TxtOutput = Round(((Me.TxtInput - 32) / 9) * 5,2) & " Celcius"
and
Me.TxtOutput = Round(((Me.TxtInput * 9) / 5) + 32,2) & " Farenheit"
and to use Int would be
Me.TxtOutput = Int(((Me.TxtInput - 32) / 9) * 5) & " Celcius"
and
Me.TxtOutput = Int(((Me.TxtInput * 9) / 5) + 32) & " Farenheit"
HTH
Alan
mraetrudeaujr
Thanks Alan.
didn't know where to put the decimal place integer and I kept getting errors. You examples worked perfect. (I'm going to try out the 'Int' function/example too!).
Again, thank you all!
Al Trudeau
Alan_G
You're very welcome - glad we were able to help