PDA

Click to See Complete Forum and Search --> : [RESOLVED] Convert Meters to Feet


toecutter
Dec 3rd, 2009, 06:47 PM
Maths was all about metric not feet and inchs when i was in school so i have no idea how to write feet and inches, i think its like 11' 11 1/16"

When i use this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mMetric As Double ="1.0" '1 meter
'convert to feet
Me.TextBox2.Text = CStr(mMetric * 3.28083)
End Sub

I get 3.28083, it will never give me a value with "x amount of feet and 11 inches" no matter what i put as the mMetric variable as it will always work on 10 units not 12.

How can i get a accurate conversion?

regards
toe

Max Peck
Dec 3rd, 2009, 07:06 PM
Here, try this:

Private Sub MetersToFeet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetersToFeet.Click

Dim metric As Double
Dim english As Double
Dim feet As Integer
Dim inches As Integer

metric = Val(txtDisplay.Text)
english = metric * 3.28083
feet = Int(english)
inches = (english - feet) * 12
txtDisplay.Text = feet & " feet " & inches & " inches"

End Sub


-Max :D

toecutter
Dec 3rd, 2009, 07:19 PM
Max, nice thank you.

I really need a result that i will be able to add together later on.

Say i had these:

2 feet 11 1/2 inches plus
3 feet 11 3/8 inches

how would i go about add those together if they where in separate textbox's?

regards
toe

jemidiah
Dec 4th, 2009, 04:49 AM
What fractions do you want to support? It'd be easier if what you wrote was instead

"2 feet 11.5 inches"
"3 feet 11.375 inches"

Fractions are possible, of course. If you really want them you can parse "11 1/2" into a whole part and a fractional part, but it's a bit unintuitive for me when I think about actually entering 11 1/2 on a form. I'd be likely to type random variants, like...

"2 feet 11 and a half inches"
"two feet 11 and 1 half inches"
"2' 11 1/2" " [2" is using 1 double quote]
"2' 11 1/2'' " [2'' is using 2 single quotes]
...

It might (depending on your usage) be easiest to split input into three parts. The first would be the number of feet entered in a text box. The second would be the number of inches in another text box. The third part would be the fraction of inches. You could do this a few ways, but one would be a pair of textboxes, one for the numerator and one for the denominator. Perhaps the denominator would be a drop-down list box with standard increments, say "4", "8", "16", "32", and "64" for fourths, eighths, sixteenths, thirty-secondths, and sixty-fourths. It could be made pretty intuitive. Imagine ______ means a textbox is there. Then your interface would say...

______' _____ ___/___"

toecutter
Dec 4th, 2009, 01:43 PM
jemidiah, i am not exactly sure what fractions i need to support as i never seen coding for this type of thing.

My target users are construction estimators in the US, i think i need to investigate what they need before designing anything.

Thanks for your help
toe

edit
How would one enter these into the standard calculator that comes with windows xp?
2' 11 1/2"
plus
2' 11 5/16''

jemidiah
Dec 4th, 2009, 07:07 PM
You couldn't enter those in the standard Windows XP calculator, not at all directly. You could add the feet and inches separately.

//Feet
2+2=4

//Inches
1/2=0.5
5/16=0.3125
11+1/2=11.5
11+5/16=11.3125

//Inches total, to feet
11.5+11.3125=22.8125=1 foot 10.8125 inches

//Sum it up and convert back to fractions
=>5 feet 10.8125 inches
= 5 feet 10 13/16 inches

toecutter
Dec 7th, 2009, 10:44 PM
You could do this a few ways, but one would be a pair of textboxes, one for the numerator and one for the denominator. Perhaps the denominator would be a drop-down list box with standard increments, say "4", "8", "16", "32", and "64" for fourths, eighths, sixteenths, thirty-secondths, and sixty-fourths. It could be made pretty intuitive. Imagine ______ means a textbox is there. Then your interface would say...

______' _____ ___/___"

This is what i have gone with

Thanks again