Last month I was visiting long time friends in Baja, Mexico, where I lived for six years. Bob and Patty have lived in Baja for nearly 15 years but still have small difficulties converting US measurements to metric units.
Patty's kitchen has a stove made in Mexico, and oven temperature is given in Centigrade, whereas all Patty's recipes are written in English and use Fahrenheit measurement. Bob often hires local laborers for construction projects, but Bob is accustomed to working in feet and inches, while the local laborers generally use meters. Both Bob and Patty thought it would be convenient if they had a small program which could make the conversions for them, instead of having to lookup the conversion factors in a reference book.
I wrote the program below in less than an hour (including time out for a lunch break and checking email); to convert the common measurements Bob and Patty use most. The program deals mostly with "kitchen arithmetic" and I figured accuracy to 2 decimal places would be adequate. I also used a menu and two dialog boxes to display instructions and miscellaneous units for conversion.
'US/Metric Converter
'Written by Welo 11/30/2005
'Enter your known value in the top box, press the button to convert
NOMAINWIN
WindowWidth=325
WindowHeight=325
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
disp$="#####.##"
BUTTON #main.btn1, "New", [new], UL, 75, 235, 60, 25
BUTTON #main.btn2, "Quit", [quit], UL, 175, 235, 60, 25
BUTTON #main.btn3, "Liter>Gal", [gal], UL, 25, 80, 100, 25
BUTTON #main.btn4, "Meter>Feet", [feet], UL, 25, 120, 100, 25
BUTTON #main.btn5, "Cent>Fah"+CHR$(176), [fah], UL, 25, 160, 100, 25
BUTTON #main.btn6, "Gal>Liter", [lit], UL, 185, 80, 100, 25
BUTTON #main.btn7, "Feet>Meter", [met], UL, 185, 120, 100, 25
BUTTON #main.btn8, "Fah>Cent"+CHR$(176), [cent], UL, 185, 160, 100, 25
BUTTON #main.btn9, "Kilo>Pound", [pound], UL, 25, 200, 100, 25
BUTTON #main.btn10, "Pound>Kilo",[kilo], UL, 185, 200, 100, 25
MENU #main, "Menu", "Instructions", [how2], "Other", [other], "Exit", [quit]
STATICTEXT #main.st1, "Known value to convert >> ", 20, 20, 200, 25
STATICTEXT #main.st2, "Value after conversion >> ", 20, 50, 200, 25
TEXTBOX #main.tb1, 230, 15, 80, 25
TEXTBOX #main.tb2, 230, 45, 80, 25
OPEN "US/Metric Converter" FOR WINDOW AS #main
PRINT #main, "trapclose [quit]"
PRINT #main, "FONT arial 10 bold"
[new]
PRINT #main.tb1, ""
PRINT #main.tb2, ""
PRINT #main.tb1, "!setfocus"
WAIT
[gal]
PRINT #main.tb1, "!contents? value"
PRINT #main.tb2, USING(disp$, (value/3.785332))
WAIT
[feet]
PRINT #main.tb1, "!contents? value"
PRINT #main.tb2, USING(disp$, (value*3.28033))
WAIT
[fah]
PRINT #main.tb1, "!contents? value"
f=32+(value/5)*9
PRINT #main.tb2, USING(disp$, f)
WAIT
[met]
PRINT #main.tb1, "!contents? value"
PRINT #main.tb2, USING(disp$, value*.3048006)
WAIT
[lit]
PRINT #main.tb1, "!contents? value"
PRINT #main.tb2, USING(disp$, (value*3.785332))
WAIT
[cent]
PRINT #main.tb1, "!contents? value"
c=((value-32)/9)*5
PRINT #main.tb2, USING(disp$, c)
WAIT
[pound]
PRINT #main.tb1, "!contents? value"
PRINT #main.tb2, USING(disp$, (value*2.2046))
WAIT
[kilo]
PRINT #main.tb1, "!contents? value"
PRINT #main.tb2, USING(disp$, (value*.4536))
WAIT
[other] 'Window for miscellaneous units of measurement
WindowWidth=325
WindowHeight=225
other$="As a general rule, use these conversion factors"+CHR$(13)+_
"for approximate measurements."+CHR$(13)+CHR$(13)+_
"One tbsp (dry) = 15 grams*"+CHR$(13)+_
"One tbsp (liq) = 12.5 grams"+CHR$(13)+_
"One cup (dry) = 225 grams*"+CHR$(13)+_
"One cup (liq) = 200 grams"+CHR$(13)+CHR$(13)+_
"*Equivalents of dry measure may vary"+CHR$(13)+_
"depending upon the ingredient being measured."
STATICTEXT #other.st0, "Other Measures", 10, 10, 300, 300
OPEN "Other Conversions" FOR DIALOG_modal AS #other
PRINT #other, "trapclose [close2]"
PRINT #other, "FONT arial 10 bold"
PRINT #other.st0, other$
WAIT
[close2]
CLOSE #other
WAIT
[how2] 'Window for instructions
WindowWidth=325
WindowHeight=120
STATICTEXT #how2.st0, "", 10, 10, 300, 100
OPEN "Instructions" FOR DIALOG_modal AS #how2
PRINT #how2, "trapclose [close3]"
PRINT #how2, "FONT arial 10 bold"
PRINT #how2.st0, "Enter your known value in the upper box,"+CHR$(13)+_
"press any button for the conversion you wish." +CHR$(13)+CHR$(13)+_
"The result will be shown in the lower box."
WAIT
[close3]
CLOSE #how2
WAIT
[quit]
CLOSE #main
END
The code is easily modified for more or fewer decimal places. You could also add additional buttons for PSI/Pascals, Kilowatts/Joules, or other units of measurement, but you will have to write your own branch routines.
A menu was added to allow the user to obtain instructions for use, and to display some miscellaneous conversion factors, instead of cluttering up the GUI with more buttons which might not be needed.
Using a window for DIALOG_modal to display information to the user, means you will not encounter a program crash if the user attempts to close the main program before closing other windows which may be open.
Because Bob and Patty could not easily locate the conversion references they were currently using, I took these conversion factors from a small, hand-written card I have carried in my wallet for years, and I believe them to be reasonably accurate. The miscellaneous units for table s p o o n s and cups to metric were taken from a cookbook by Fannie Farmer, published in 1990 and I can't guarantee the accuracy of her kitchen arithmetic.