View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
RyanH RyanH is offline
external usenet poster
 
Posts: 586
Default Numbers Not Calculating Correct on Userform

We build outdoor signs here so we would like to round up to the nearest 1/16
of an inch. I would like my code to be "universal" so my users can enter the
length in decimal format or foot & inch format. For example, the user will
enter 5.5 in the HeightFt textbox and the code returns 5 ft - 6 inches or the
user will enter 5 in the HeightFt textbox and 6 in the HeightIns textbox and
the code returns 5 ft - 6 inches.

Here is a simpler form of code of what I am trying to do. For some reason
Hins and Wins do NOT equal when I enter the same number in tbxHeightIns and
tbxWidthIns. Such as .125 or .0625.

Private Sub cmbEstimate_Click()

Dim Lheight As Double
Dim Lwidth As Double
Dim Hft As Double
Dim Hins As Double
Dim Wft As Double
Dim Wins As Double

Lheight = Val(tbxHeightFt) + Val(tbxHeightIns) / 12 'face height in ft
'MsgBox Lheight
Lwidth = Val(tbxWidthFt) + Val(tbxWidthIns) / 12 'face width in ft
'MsgBox Lwidth

'dimensions of cabinet in feet & inches
Hft = Int(Lheight)
MsgBox Hft
Hins = WorksheetFunction.Ceiling((Lheight - Hft) * 12, 0.0625)
MsgBox Hins
Wft = Int(Lwidth)
MsgBox Wft
Wins = WorksheetFunction.Ceiling((Lwidth - Wft) * 12, 0.0625)
MsgBox (Wins)

End Sub

Thanks,
Ryan


"Ronald R. Dodge, Jr." wrote:

The only place where the 1/16 would come from would be either if you are
measuring in fractions of an inch or it's from "16 ounces = 1 pound". .0625
= 1/16. I never really knew about the CEILING function until now, but with
what I see how it's used, I could only think of limited cases to use it such
as in carpentry where you would measure in 16ths and you wouldn't want to
cut boards too short, so rounding up to the next 16ths in such a case would
make sense.

If you want to have it show as "1 ft 1 inch", then use the following:

MsgBox tbxWidthFt & " ft " & tbxWidthIns & " inch", vbOK

If you want to have it show as "1.0833 ft", then use the following

width = Val(tbxWidthFt) + Int(Val(tbxWidthIns) / 12*10000)/10000 'face
width in ft
MsgBox CStr(width) & " ft", vbOK

Note, multiplications and divisions takes precedence over additions and
subtractions

If you have a decimal form number and you need to take it to the "# ft #
inch" format going to the nearest inch, then use the following:

MsgBox Int(width) & " ft " & Int((width - Int(width))*12+0.5) & " inch"

Sincerely,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"RyanH" wrote in message
...
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