Set Decimal Places


R

Reject

I am using Access 2000 database for calibration control of measuring
instruments. i.e. micrometers, calipers etc. The precision of the instruments
varies and the decimal data fields in the table are set to Auto to minimize
the stored values without changing the accuracy.

I want to change the number of decimal places displayed in the individual
instrument report using an IF statement where the criteria is controlled by
the decimal precision required for the specific instrument.

How can I do this?

So far I have not found the command to set decimal in VB let alone structure
the entire IF statement.
 
Ad

Advertisements

J

Jack Leach

Take a look at the Format() function. It should do what you want, assuming
you have a field for denoting the tolerance required. Something like this:

Set the text box on the report like so:

=FormatDecimal([Numberfield], [Tolerancefield])

This assumes that Numberfield is the name of the field in the report holding
the value to format, and Tolerancefield is the name of the field that holds
your tolerance class.

Then write a public function in a standard module like so (aircode):

Public Function FormatDecimal(
dNumber As Double, _
iTolClass As Integer _
) As String

Select Case iTolClass
Case 1 '1pl decmials
FormatDecimal = Format(dNumber, "0.0")
Case 2 '2pl decimal
FormatDecimal = Format(dNumber, "0.00")
Case 3 '3pl decmial
FormatDecimal = Format(dNumber, "0.000")
End Select
End Function


hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
M

Marshall Barton

Jack Leach said:
Take a look at the Format() function. It should do what you want, assuming
you have a field for denoting the tolerance required. Something like this:

Set the text box on the report like so:

=FormatDecimal([Numberfield], [Tolerancefield])

This assumes that Numberfield is the name of the field in the report holding
the value to format, and Tolerancefield is the name of the field that holds
your tolerance class.

Then write a public function in a standard module like so (aircode):

Public Function FormatDecimal(
dNumber As Double, _
iTolClass As Integer _
) As String

Select Case iTolClass
Case 1 '1pl decmials
FormatDecimal = Format(dNumber, "0.0")
Case 2 '2pl decimal
FormatDecimal = Format(dNumber, "0.00")
Case 3 '3pl decmial
FormatDecimal = Format(dNumber, "0.000")
End Select
End Function


As long as the iTolClass argument is guaranteed to be to be
in a reasonable range, that could be simplified a little:

Public Function FormatDecimal(
dNumber As Double, _
iTolClass As Integer _
) As String

FormatDecimal=Format(dNumber,"0." & String(iTolClass,"0"))
End Function
 
Ad

Advertisements

J

Jack Leach

FormatDecimal=Format(dNumber,"0." & String(iTolClass,"0"))
End Function

In which case op could get rid of the public function altogether and instead
make this the control source of an unbound control on the report

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



Marshall Barton said:
Jack Leach said:
Take a look at the Format() function. It should do what you want, assuming
you have a field for denoting the tolerance required. Something like this:

Set the text box on the report like so:

=FormatDecimal([Numberfield], [Tolerancefield])

This assumes that Numberfield is the name of the field in the report holding
the value to format, and Tolerancefield is the name of the field that holds
your tolerance class.

Then write a public function in a standard module like so (aircode):

Public Function FormatDecimal(
dNumber As Double, _
iTolClass As Integer _
) As String

Select Case iTolClass
Case 1 '1pl decmials
FormatDecimal = Format(dNumber, "0.0")
Case 2 '2pl decimal
FormatDecimal = Format(dNumber, "0.00")
Case 3 '3pl decmial
FormatDecimal = Format(dNumber, "0.000")
End Select
End Function


As long as the iTolClass argument is guaranteed to be to be
in a reasonable range, that could be simplified a little:

Public Function FormatDecimal(
dNumber As Double, _
iTolClass As Integer _
) As String

FormatDecimal=Format(dNumber,"0." & String(iTolClass,"0"))
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top