Visual Basic 6.0

To make a simple temperature conversion program, create a project with the following objects:

Then Copy/Paste this code:

eMbedded Visual Basic 3.0

Make the same form and Copy/Paste the same code as above, but replace the Private Sub txtData_KeyUp event line with this one:

What's Happening?

The optF_Click event (when the °F option is selected), the optC_Click event (when the °C option is selected), and the txtData_KeyUp event (when focus is on the text box and a key is pressed and released on the keyboard) trigger the Convert() code. The code checks if the conversion is °F to °C or °C to °F based on the option selection. The code also makes sure the data in the text box is a number (otherwise letters, a negative sign, or an empty text box from using back space would cause an error) - if it is not a number, it uses a zero value. Then the code converts the data, changes the lblAnswer caption to the answer, and changes the lblUnit caption to the appropriate unit (oppossite of selection).

Just a note - you can type the "°" character by holding down Alt key and typing "248" on the Num Pad, and then releasing the Alt key (you can also use "0176").