October 11th, 1999, 07:56 PM
I am trying to write a small program that will convert the entered miles, yards, feet, and inches into kilometers, meters, and centimeters. The number for kilometers comes out fine, but the meters are way off. What doesn't make sense is that the kilometers are found by using the data from meters. The code is as follows:
private Sub cmdConvert_Click()
miles = Val(txtMiles.Text)
yards = Val(txtYards.Text)
feet = Val(txtFeet.Text)
inches = Val(txtInches.Text)
totalInches = Val(63360 * miles + 36 * yards + 12 * feet + inches) ' takes all valuse entered into the text boxes and converts them to inches
totalMeters = Int(totalInches / 39.37) ' this does not come out right, but kilometers do, even though kilometers (below) use this value.
kilometers = Int(totalMeters / 1000) ' works fine.
centimeters = Int(kilometers / 0.01) ' comes out a little higher than it should.
picDisplay.print "The metric length is:"
picDisplay.print kilometers; "kilometers,"
picDisplay.print totalMeters; "meters, and"
picDisplay.print centimeters; "centimeters."
End Sub
If you enter 5 in the box for miles, 20 for yards, 2 for feet, and 4 for inches, the values should read 8 kilometers, 65 meters, and 73.5 centimeters. Can anyone help me?
Thanks!
private Sub cmdConvert_Click()
miles = Val(txtMiles.Text)
yards = Val(txtYards.Text)
feet = Val(txtFeet.Text)
inches = Val(txtInches.Text)
totalInches = Val(63360 * miles + 36 * yards + 12 * feet + inches) ' takes all valuse entered into the text boxes and converts them to inches
totalMeters = Int(totalInches / 39.37) ' this does not come out right, but kilometers do, even though kilometers (below) use this value.
kilometers = Int(totalMeters / 1000) ' works fine.
centimeters = Int(kilometers / 0.01) ' comes out a little higher than it should.
picDisplay.print "The metric length is:"
picDisplay.print kilometers; "kilometers,"
picDisplay.print totalMeters; "meters, and"
picDisplay.print centimeters; "centimeters."
End Sub
If you enter 5 in the box for miles, 20 for yards, 2 for feet, and 4 for inches, the values should read 8 kilometers, 65 meters, and 73.5 centimeters. Can anyone help me?
Thanks!