Although most of the world is now metric, Americans still use the old imperial system. When cooking, if you are using a recipe from USA the oven temperatures are given in degrees Fahrenheit, whereas Australian ovens measure in degrees Celsius. We are going to create a simple program that converts oven temperatures from Fahrenheit to Celsius (so we don't burn all our cakes!).
Designing the Interface:
First of all we will design the interface. We will use a text box for the user to enter in the temperature they want to convert.
![]() |
|
We need to set up something like this:

The heading at the top is a label, as is Enter degrees Fahrenheit and Celsius. The background colours for the labels is set to be the same as the background colours for the form.
The top white box is a text box with the following properties set:
| Name | txtFah |
| Alignment | Center |
| BackColor | White |
| Font | Size 18, Bold |
| Text | leave blank |
The lower white box is a label with the following properties set: (We chose a label because we don't want the user to type in it)
| Name | lblCelsius |
| Alignment | Center |
| Appearance | 1 -3D |
| BackColor | White |
| Font | Size 18, Bold |
| Caption | leave blank |
Add two command buttons with the following properties:
|
|
You can use this image by right clicking and saving it to your home drive, or you can choose an image of your own.

Writing the Code
Before writing the code, check that you have named the top white box txtFah, the lower white box lblCelsius, the convert button cmdConvert and the Exit button cmdExit.
The formula for converting Fahrenheit to Celsius is:
C=(F-32)*0.56 (* means multiply)
So to convert a Fahrenheit temperature of 350 degrees into degrees Celsius first subtract 32 from the Fahrenheit temperature to get 318 Then you multiply 318 by 0.56 to get 177 degrees Celsius.
-
Double click on the convert button and put in this code:
Private Sub cmdConvert_Click()
lblCelsius.Caption = (txtFah.Text - 32) * 0.56
End SubThe code takes the text from the txtFah box, subtracts 32 from it and multiplies by 0.56. It places the answer in the caption for lblCelsius
The = sign as used in the lblCelsius.caption statement is being used to assign values to the caption property of the label. Assigning is the giving of a value. So lblCelsius.caption = 23 would mean that the lblCelsius caption is assigned (or given) the value 23.
-
Double click the cmdExit button and put in this code:
Private Sub cmdExit_Click()
Unload Me
End Sub
This code exits the program.
Test Your Program
Now try running your program. Provided you have taken care to spell everything correctly and name your controls carefully, it should all work.
If you get an error message like this when you try to run your program, it is likely that you have misspelled the name of one of your objects somewhere.
What you will notice when you run the program is that you get decimal values for your answer. Because ovens are not that accurate, a whole number value would make more sense. You can prevent decimals appearing by changing the line of code for the conversion to:
lblCelsius.Caption = int((txtFah.Text - 32) * 0.56)
The int() function converts a number to an integer (whole number) value.
Save Your Project as TempConverter
US recipes also include other measurements that need to be converted.
Ounces to grams (1 ounce = 28 grams)
Fluid Ounces to millilitres (1 fluid ounce = 28 millilitres)
Modify your temperature converter to become a cooking converter so that it will also enable the user to convert ounces to grams and fluid ounces to mls. You may need to enlarge your form, and add some lines or shapes to organise things on it.
Modify the program so that it can handle pounds and ounces, and pints as well. (1 pound = 16 ounces, 1 pint = 20 fluid ounces)





