Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 7 Using Loops and Timers 195


entering no value returns an empty string (“”). The loop checks for the empty string by
using a While conditional test at the bottom of the loop. The program statement:

Celsius = Int((FTemp + 40) * 5 / 9 - 40)
handles the conversion from Fahrenheit to Celsius in the program. This statement
employs a standard conversion formula, but it uses the Int function to return a value
that contains no decimal places to the Celsius variable. (Everything to the right of the
decimal point is discarded .) This cutting sacrifices accuracy, but it helps you avoid long,
unsightly numbers such as 21 .11111, the Celsius value for 70 degrees Fahrenheit.


  1. Click the Save All button on the Standard toolbar to save your changes. Specify the
    C:\Vb10sbs\Chap07 folder as the location.
    Now you’ll try running the program.


Tip The complete Celsius Conversion program is available in the C:\Vb10sbs\Chap07\
Celsius Conversion folder.


  1. Click the Start Debugging button on the Standard toolbar.


The program starts, and the InputBox function prompts you for a Fahrenheit
temperature.


  1. Type 212.


Your screen looks like this:


  1. Click OK.


The temperature 212 degrees Fahrenheit is converted to 100 degrees Celsius, as shown
in this message box:
Free download pdf