Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Inputbox Convert Millimeters to Feet and Inches

Greetings,
I posted here earlier and had a wonderful response. Thank you Harold. That
code did the trick.
New Scenerio:
How can you convert Millimeters from an input box and show the values
broken out among four textboxes.
The four textboxes are labeled Feet, Inches, Top Fraction, and Bottom
Fraction, respectfully.

1669.598 MM in textbox should convert to 5' 5 1/2 " (I'm pretty sure
that's correct)
Textbox Feet = 5
Textbox Inches = 5
Textbox Top Fraction = 1
Textbox Bottom Fraction = 2

Any help is greatly appreciated.
Thank you for your time.





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Inputbox Convert Millimeters to Feet and Inches

I created a little form with txtMM as the input and txtFT, txtIn,
txtNumerator (aka top fraction), and txtDenominator (aka bottom
fraction) as the outputs. The following is the conversion code (using a
command button - cmdCalc) to drive it:

Private Sub cmdCalc_Click()

Const CONV_FACTOR As Double = 304.8 'mm to ft
Const PROXIMITY As Double = 0.1
Const MAX_ITERATIONS As Integer = 1000

Dim mm As Double
Dim feet As Double
Dim inches As Double
Dim numerator As Double
Dim denominator As Integer
Dim remainder As Double

If Not IsNumeric(Me.txtMM) Then
MsgBox "Error"
Exit Sub
End If

mm = CDbl(Me.txtMM)
feet = mm / CONV_FACTOR
Me.txtFt = Int(feet)

remainder = feet - CInt(feet)
inches = remainder * 12
Me.txtIn = Int(inches)

remainder = inches - Int(inches)
denominator = 1
Do
denominator = denominator + 1
numerator = remainder * denominator
Loop While Abs(numerator - Round(numerator, 0)) PROXIMITY _
And (denominator <= MAX_ITERATIONS)

If denominator = MAX_ITERATIONS Then
MsgBox "Cannot calculate to desired proximity"
Else
Me.txtNumerator = CInt(numerator)
Me.txtDenominator = denominator
End If

End Sub

The PROXIMITY value is how close you want the numerator to be to a
whole number. The smaller the number, the more funky (but more
accurate) results you'll get. The MAX_ITERATIONS is the maximum number
of times you want the loop to run.

I get 5' 5-3/4", which I verified as correct.


----
Nick Hebb
BreezeTree Software
http://www.breezetree.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert decimal inches into feet and inches Jason Stripling Excel Discussion (Misc queries) 2 April 23rd 09 02:45 PM
Convert inches & display as Feet Inches and Fractions -- BUG FREE Mark Main Excel Worksheet Functions 12 November 26th 08 08:50 PM
How do I convert decimal to feet and inches Erik Excel Worksheet Functions 5 October 25th 07 11:54 PM
convert to feet and inches sjl Excel Discussion (Misc queries) 3 February 17th 07 12:31 AM
is there a macro that will convert from inches to feet and inches cable guy Excel Discussion (Misc queries) 1 June 20th 05 07:29 PM


All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"