Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I got it to work now. This is what I did.
Public Sub Preview() Dim height As Single Dim width As Single Dim Hft As Byte Dim Hins As Single Dim Wft As Byte Dim Wins As Single Dim Face As String 'result of which face was selected on userform If optSingleFace = True Then Face = optSingleFace.Caption Else Face = optDoubleFace.Caption End If 'round height & width to the nearest 1/16th of an inch height = Round(Val(tbxHeightFt) * 12 * 16 + Val(tbxHeightIns) * 16) 'height in 1/16th of inches width = Round(Val(tbxWidthFt) * 12 * 16 + Val(tbxWidthIns) * 16) 'width in 1/16th of inches 'dimensions of cabinet in feet & inches Hft = Int(height / 16 / 12) Hins = (Round((height / 16 / 12 - Hft) * 12 * 16)) / 16 Wft = Int(width / 16 / 12) Wins = (Round((width / 16 / 12 - Wft) * 12 * 16)) / 16 'Preview Line 1: Single/Double Face, Extruded Cabinet: Dimensions lblPreview1.Caption = Face & ", Extruded Cabinet: " & Hft & "'-" & Hins & "'' H x " & Wft & "'-" & Wins & "'' W x " & Val(tbxDepthIns) & "'' D" End Sub Thanks, Ryan "Mark Lincoln" wrote: This may be a situation where your code actually produces a number just slightly greater than 1, (1.00000003, say) which CEILING then rounds to 1.0625 as instructed. That's a problem sometimes with representing decimal numbers in binary. You may want to round to the nearest .0625 inch as opposed to rounding up to the next .0625 in. as CEILING does. Conversely, you may want to subtract a very small fraction from the number you're processing with CEILING in order to try to counteract the problem. Mark Lincoln On Feb 12, 9:53 pm, RyanH wrote: width should be calculated in feet. Yes, I had a 1 in the WidthFT textbox. For some reason when I enter a 1 in the WidthFT textbox and 1 in the widthIns textbox my label shows 1 ft and 1.0625 inches. It should say 1 ft 1 inch. Why is this happening? Thanks Ryan "Ronald R. Dodge, Jr." wrote: Are you attempting to show this in inches or in feet? Your statement says one thing, and the code shows another. Also, when you got the result, did you have a "1" in the Width(Ft) text box? width = Val(tbxWidthFt) + Val(tbxWidthIns) / 12 'face width in ft MsgBox width "RyanH" wrote in message ... I have a Userform with 4 Textboxes labeled Height(Ft), Height(Ins), Width(Ft), and Width(Ins). I have a Label Caption that I use to combine the results of what was entered in the 4 textboxes when I click a command button. For some reason when I enter 1 in the Width(Ins) Textbox the label will show 1.0625" instead of 1". Public Sub Preview() Dim height As Double Dim width As Double Dim Hft As Double Dim Hins As Double Dim Wft As Double Dim Wins As Double Dim Face As String 'result of which face was selected on userform If optSingleFace = True Then Face = optSingleFace.Caption Else Face = optDoubleFace.Caption End If height = Val(tbxHeightFt) + Val(tbxHeightIns) / 12 'face height in ft MsgBox height width = Val(tbxWidthFt) + Val(tbxWidthIns) / 12 'face width in ft MsgBox width 'dimensions of cabinet in feet & inches Hft = Int(height) MsgBox Hft Hins = WorksheetFunction.Ceiling((height - Hft) * 12, 0.0625) MsgBox Hins Wft = Int(width) MsgBox Wft Wins = WorksheetFunction.Ceiling((width - Wft) * 12, 0.0625) MsgBox (Wins) 'Preview Line 1: Single/Double Face, Extruded Cabinet: Dimensions lblPreview1.Caption = Face & ", Extruded Cabinet: " & Hft & "'-" & Hins & "'' H x " & Wft & "'-" & Wins & "'' W x " & Val(tbxDepthIns) & "'' D" End Sub Thanks, Ryan- Hide quoted text - - Show quoted text - |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
IF function inequality is not calculating correct result | Excel Discussion (Misc queries) | |||
textbox show correct time in userform | Excel Programming | |||
Userform to grab,correct and restore data | Excel Programming | |||
Calculating correct pecentages with negative values | Excel Worksheet Functions | |||
Which formula is correct for calculating times? | Excel Discussion (Misc queries) |