billcute
asked on
Round off and Decimal places
Users currently use the following code to compare two values ....
Private Sub txt_B_Exit(Cancel As Integer)
Dim myLimit, myValue, myTol
myLimit = 10
myTol = 0.00005
If Nz(Me.txt_B) < myLimit Then
MsgBox "Sqarefeetvalues below " & myLimit & " are not possible in this context!", vbExclamation
Cancel = True
Else
'Calculate formula
myValue = (.............)
myValue = Round(myValue, 5)
' Compare result with tolerance '<<----- Critcal point
If Abs(myValue - Me.txt_A.Value) > myTol Then
MsgBox "The calculatd Value is " & myValue, vbCritical
Me.txt_A.SetFocus
Else
Me.Verified = True
Me.txt_C.SetFocus
End If
End If
End Sub
************************** ****
Our office usually round off to 5 decimal places all the time during data entry but adhere to the 3 decimal places when compiling a report. Most of the Engineers / Architects who request for permits from us usually round off to 3 decimal places when submiting their value of their new project "Flow" for us to validate.
Assuming that an Engineer submitted a flow of 0.006 but the auto calculated value
came out to be 0.00561.
In actual sense, the value of 0.006 submitted by the Engineer is correct if 0.00561 was
rounded off to 3 decimal places.
Using tolerance of value > 0.00005 through 0.00099 did not resolve the 3 decimal places
and as a result, the autocalculated value of 0.000561 did not accept the 0.00600 as correct or equals to 0.00561.
QUESTION?
In this scenerio, in what way can I adjust the tolerance value to recond the following:
if the autocalculated value is 0.00561 then
(a). Accept the rounding off to 0.00600
(b) Deny rounding off to 0.00610
(c).Deny rounding off to 0.00500
(d). Accept rounding to 0.00560
(f). Deny rounding to 0.00562 since it was greater than the original
calculated value of 0.00561
Well, I am not too sure if the above is achievable, I was only pondering on it.
Private Sub txt_B_Exit(Cancel As Integer)
Dim myLimit, myValue, myTol
myLimit = 10
myTol = 0.00005
If Nz(Me.txt_B) < myLimit Then
MsgBox "Sqarefeetvalues below " & myLimit & " are not possible in this context!", vbExclamation
Cancel = True
Else
'Calculate formula
myValue = (.............)
myValue = Round(myValue, 5)
' Compare result with tolerance '<<----- Critcal point
If Abs(myValue - Me.txt_A.Value) > myTol Then
MsgBox "The calculatd Value is " & myValue, vbCritical
Me.txt_A.SetFocus
Else
Me.Verified = True
Me.txt_C.SetFocus
End If
End If
End Sub
**************************
Our office usually round off to 5 decimal places all the time during data entry but adhere to the 3 decimal places when compiling a report. Most of the Engineers / Architects who request for permits from us usually round off to 3 decimal places when submiting their value of their new project "Flow" for us to validate.
Assuming that an Engineer submitted a flow of 0.006 but the auto calculated value
came out to be 0.00561.
In actual sense, the value of 0.006 submitted by the Engineer is correct if 0.00561 was
rounded off to 3 decimal places.
Using tolerance of value > 0.00005 through 0.00099 did not resolve the 3 decimal places
and as a result, the autocalculated value of 0.000561 did not accept the 0.00600 as correct or equals to 0.00561.
QUESTION?
In this scenerio, in what way can I adjust the tolerance value to recond the following:
if the autocalculated value is 0.00561 then
(a). Accept the rounding off to 0.00600
(b) Deny rounding off to 0.00610
(c).Deny rounding off to 0.00500
(d). Accept rounding to 0.00560
(f). Deny rounding to 0.00562 since it was greater than the original
calculated value of 0.00561
Well, I am not too sure if the above is achievable, I was only pondering on it.
What is this supposed to do?
myValue = (.............)
myValue = (.............)
ASKER
Franz,
Thanks for your response. Your suggested code looks very good, I tried testing but ran into a small difficully. I suspect that the unfinished part of the code for "conhere" are message boxes.
Kindly provide suggestions to "conhere" so that I could test further.
Regards
Bill
Thanks for your response. Your suggested code looks very good, I tried testing but ran into a small difficully. I suspect that the unfinished part of the code for "conhere" are message boxes.
Kindly provide suggestions to "conhere" so that I could test further.
Regards
Bill
ASKER
GRayL:
Thanks for your enquiry.
myValue = (.............)
....is expected to calculate a formular " Something like (a x b x c/14)
The return value is what users will need to have compare with his original entry (that is: flow suplied by the engineer).
Regards
Bill
Thanks for your enquiry.
myValue = (.............)
....is expected to calculate a formular " Something like (a x b x c/14)
The return value is what users will need to have compare with his original entry (that is: flow suplied by the engineer).
Regards
Bill
Private Sub txt_B_Exit(Cancel As Integer)
Dim myLimit, myValue, myTol
myLimit = 10
-------------------------- ---------- ---here starts new part
--------------- this is replaced >>>>>>>> myTol = 0.00005
If Int(myValue*10000)<>myValu e*10000 Then
myTol = 0.00005
Goto conhere
End If
If Int(myValue*1000)<>myValue *1000 Then
myTol = 0.0005
Goto conhere
End If
If Int(myValue*100)<>myValue* 100 Then
myTol = 0.005
Goto conhere
End If
conhere:
-------------------------- ---------- ---------- ------- End of new part
If Nz(Me.txt_B) < myLimit Then
MsgBox "Sqarefeetvalues below " & myLimit & " are not possible in this context!", vbExclamation
Cancel = True
Else
'Calculate formula
myValue = (.............)
myValue = Round(myValue, 5)
' Compare result with tolerance '<<----- Critcal point
If Abs(myValue - Me.txt_A.Value) > myTol Then
MsgBox "The calculatd Value is " & myValue, vbCritical
Me.txt_A.SetFocus
Else
Me.Verified = True
Me.txt_C.SetFocus
End If
End If
End Sub
the 3 if-statements look, if the last significant decimal is 5th, 4th or 3rd digit and set the tollerance acordingly
regards, Franz
Dim myLimit, myValue, myTol
myLimit = 10
--------------------------
--------------- this is replaced >>>>>>>> myTol = 0.00005
If Int(myValue*10000)<>myValu
myTol = 0.00005
Goto conhere
End If
If Int(myValue*1000)<>myValue
myTol = 0.0005
Goto conhere
End If
If Int(myValue*100)<>myValue*
myTol = 0.005
Goto conhere
End If
conhere:
--------------------------
If Nz(Me.txt_B) < myLimit Then
MsgBox "Sqarefeetvalues below " & myLimit & " are not possible in this context!", vbExclamation
Cancel = True
Else
'Calculate formula
myValue = (.............)
myValue = Round(myValue, 5)
' Compare result with tolerance '<<----- Critcal point
If Abs(myValue - Me.txt_A.Value) > myTol Then
MsgBox "The calculatd Value is " & myValue, vbCritical
Me.txt_A.SetFocus
Else
Me.Verified = True
Me.txt_C.SetFocus
End If
End If
End Sub
the 3 if-statements look, if the last significant decimal is 5th, 4th or 3rd digit and set the tollerance acordingly
regards, Franz
ASKER
Franz,
I ran a quick test with the following values and still have some problems with the auto calculation and the compared value:
I selected R3-2; and entered 2465 in my formular (not shown here)
Engineer's flow data = 0.003 (rounded to to 3 d(to 5 decimal places).
Auto calculated flow value = 0.00261(to 5 decimal places)
Judging by the two values above, both the Engineer's flow value and the autocalculated value are correct but the code above still presented me with a msgbox as if the Engineer's value was wrong.
Am I doing something wrong?
Regards
Bill
I ran a quick test with the following values and still have some problems with the auto calculation and the compared value:
I selected R3-2; and entered 2465 in my formular (not shown here)
Engineer's flow data = 0.003 (rounded to to 3 d(to 5 decimal places).
Auto calculated flow value = 0.00261(to 5 decimal places)
Judging by the two values above, both the Engineer's flow value and the autocalculated value are correct but the code above still presented me with a msgbox as if the Engineer's value was wrong.
Am I doing something wrong?
Regards
Bill
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Franz,
Thanks for your suggestions. I am quite satisifed with this and I appreciate the samples you provided here.
Regards
Bill
Thanks for your suggestions. I am quite satisifed with this and I appreciate the samples you provided here.
Regards
Bill
Probably simplest way may be:
If Int(myValue*10000)<>myValu
myTol = 0.00005
Goto conhere
End If
If Int(myValue*1000)<>myValue
myTol = 0.0005
Goto conhere
End If
If Int(myValue*100)<>myValue*
myTol = 0.005
Goto conhere
End If
conhere:
...
...
Regards, Franz