tolerance place counting

J

JohnE

I have an engineering tolerance test result that needs to be kept as a
decimal but the field is dropping the last zero entered. An example is if
the user types in 0.010, the last 0 is getting dropped. That 0 must be
there. (In engineering tolerance testing of med devices there is a
difference between .010 and .01.)

There is another field (hidden) that is to store the number of places after
the decimal point. So in the example above it should have 3 in the hidden
textbox. The code below is in the AfterUpdate event of the tolerance field
the user would enter the 0.010 but the hidden field will show 2 instead of 3.
If the user typed in 0.001, the hidden field shows 3, which is correct.
Mainly, if the last digit typed is 0, then it drops off and the count in the
hidden field is short by one.

Dim decCount As Long
decCount = Nz(Len(Mid([UpperTolerance], InStr([UpperTolerance], ".") + 1)), 0)
SignificantDigits.Value = decCount

Am I missing something in the code above that would count the ending 0? I
tried this in the BeforeUpdate of the tolerance field and got the same
result. I need help on this.

Thanks.

John

K

KARL DEWEY

The Nz function returns a 'number' and numbers do not have leading zeros or
trailing decimal zeros. A text field can display both leading and trailing
zeros.

UNTESTED - But I think you can use the hidden field value like this --

Int([UpperTolerance]) & "." & Left([UpperTolerance] -
Int([UpperTolerance]) & "000", SignificantDigits.Value)

J

JohnE

Thanks for the reply. I gave your suggestion a try and got 'Invalid Use of
Null" error message. I placed the line below into the UpperTolerance
AfterUpdate event. Or would it be better in the hidden field
(SignificantDigits) event of some type?

SignificantDigits.Value = Int([UpperTolerance]) & "." &
Left([UpperTolerance] - Int([UpperTolerance]) & "000",
SignificantDigits.Value)

Thanks.
John

KARL DEWEY said:
The Nz function returns a 'number' and numbers do not have leading zeros or
trailing decimal zeros. A text field can display both leading and trailing
zeros.

UNTESTED - But I think you can use the hidden field value like this --

Int([UpperTolerance]) & "." & Left([UpperTolerance] -
Int([UpperTolerance]) & "000", SignificantDigits.Value)

--
Build a little, test a little.

JohnE said:
I have an engineering tolerance test result that needs to be kept as a
decimal but the field is dropping the last zero entered. An example is if
the user types in 0.010, the last 0 is getting dropped. That 0 must be
there. (In engineering tolerance testing of med devices there is a
difference between .010 and .01.)

There is another field (hidden) that is to store the number of places after
the decimal point. So in the example above it should have 3 in the hidden
textbox. The code below is in the AfterUpdate event of the tolerance field
the user would enter the 0.010 but the hidden field will show 2 instead of 3.
If the user typed in 0.001, the hidden field shows 3, which is correct.
Mainly, if the last digit typed is 0, then it drops off and the count in the
hidden field is short by one.

Dim decCount As Long
decCount = Nz(Len(Mid([UpperTolerance], InStr([UpperTolerance], ".") + 1)), 0)
SignificantDigits.Value = decCount

Am I missing something in the code above that would count the ending 0? I
tried this in the BeforeUpdate of the tolerance field and got the same
result. I need help on this.

Thanks.

John

C

Chris Hall

look, I am about to star classes soon. I know nothing about engineering this
"code" or anything like this so please dont be angry with me.
Ok
If something like this happens to me in life I do this
I take what bull s**t story I hear and I manipulate what I think is true or
not meaning
tell the user to input, leting them put in they'r dec. n all BUT
Don't actually count they're decimal, count urs, then manipulate urs so
placeholder losses can not happen
like if user inputs 000.100 Take out the . from they're input. See it as
000100.
then do a little math and bada bing your prog has the exact #
Again, sorry for butting my nose in while being dumb
later

C

Chris Hall

look, I am about to star classes soon. I know nothing about engineering this
"code" or anything like this so please dont be angry with me.
Ok
If something like this happens to me in life I do this
I take what bull s**t story I hear and I manipulate what I think is true or
not meaning
tell the user to input, leting them put in they'r dec. n all BUT
Don't actually count they're decimal, count urs, then manipulate urs so
placeholder losses can not happen
like if user inputs 000.100 Take out the . from they're input. See it as
000100.
then do a little math and bada bing your prog has the exact #
Again, sorry for butting my nose in while being dumb
later

K

KARL DEWEY

I assumed that SignificantDigits.Value was the hidden field telling it
how many decimal places to show.

What I posted would calculate the results for a field.
Int([UpperTolerance]) & "." & Left([UpperTolerance] -
Int([UpperTolerance]) & "000", SignificantDigits.Value)

Int([UpperTolerance]) gives you the integer portion of the value.
& "." & adds a decimal to the integer.
([UpperTolerance] - Int([UpperTolerance]) subtracts the integer from the
whole number leaving the decimal.
& "000", adds zeros to the string.
SignificantDigits.Value) controls how much of the left side of the
decimal value and zeros to display in the results.

I do not know how to place it in code.

--
Build a little, test a little.

JohnE said:
Thanks for the reply. I gave your suggestion a try and got 'Invalid Use of
Null" error message. I placed the line below into the UpperTolerance
AfterUpdate event. Or would it be better in the hidden field
(SignificantDigits) event of some type?

SignificantDigits.Value = Int([UpperTolerance]) & "." &
Left([UpperTolerance] - Int([UpperTolerance]) & "000",
SignificantDigits.Value)

Thanks.
John

KARL DEWEY said:
The Nz function returns a 'number' and numbers do not have leading zeros or
trailing decimal zeros. A text field can display both leading and trailing
zeros.

UNTESTED - But I think you can use the hidden field value like this --

Int([UpperTolerance]) & "." & Left([UpperTolerance] -
Int([UpperTolerance]) & "000", SignificantDigits.Value)

--
Build a little, test a little.

JohnE said:
I have an engineering tolerance test result that needs to be kept as a
decimal but the field is dropping the last zero entered. An example is if
the user types in 0.010, the last 0 is getting dropped. That 0 must be
there. (In engineering tolerance testing of med devices there is a
difference between .010 and .01.)

There is another field (hidden) that is to store the number of places after
the decimal point. So in the example above it should have 3 in the hidden
textbox. The code below is in the AfterUpdate event of the tolerance field
the user would enter the 0.010 but the hidden field will show 2 instead of 3.
If the user typed in 0.001, the hidden field shows 3, which is correct.
Mainly, if the last digit typed is 0, then it drops off and the count in the
hidden field is short by one.

Dim decCount As Long
decCount = Nz(Len(Mid([UpperTolerance], InStr([UpperTolerance], ".") + 1)), 0)
SignificantDigits.Value = decCount

Am I missing something in the code above that would count the ending 0? I
tried this in the BeforeUpdate of the tolerance field and got the same
result. I need help on this.

Thanks.

John

J

Jim Franklin

John, the way I understand it, you need to record the number of digits keyed
in after the decimal point, regardless of whether that digit is a 0 or not.
Am I right?

Could you not use the key press event for the control to test whether the
key pressed is the '.' - if it is then count the number of keystrokes after
the '.' is pressed before the control is updated, using a variable declared
with scope over the form module. Doing it this way you can also test each
keystroke to ensure it is a valid one (e.g. 0-9 or a '.')

Alternatively could you store the original input as a string and then
convert it to a numeric when required?

As far as I am aware, when you enter a value into a control bound to a
number type field, Access only stores the numeric element. Trailing zeros
are dropped instantly.

For example, if you enter the value 1.01000 in a control bound to a number
field, the following code returns a message of 4, regardless of whether it
is in the BeforeUpdate or AfterUpdate event:

Dim str1 As String
str1 = CStr(Me.UpperTolerance)
MsgBox Len(str1)

Hope some of this makes sense!

Jim

J

JohnE

I got it figured out and used the following.

Dim decCount As Long
decCount = Len(Mid(UpperTolerance.Text, InStr(UpperTolerance.Text, ".") + 1))
SignificantDigits.Value = decCount

It works.
Thanks for the help.
John

KARL DEWEY said:
I assumed that SignificantDigits.Value was the hidden field telling it
how many decimal places to show.

What I posted would calculate the results for a field.
Int([UpperTolerance]) & "." & Left([UpperTolerance] -
Int([UpperTolerance]) & "000", SignificantDigits.Value)

Int([UpperTolerance]) gives you the integer portion of the value.
& "." & adds a decimal to the integer.
([UpperTolerance] - Int([UpperTolerance]) subtracts the integer from the
whole number leaving the decimal.
& "000", adds zeros to the string.
SignificantDigits.Value) controls how much of the left side of the
decimal value and zeros to display in the results.

I do not know how to place it in code.

--
Build a little, test a little.

JohnE said:
Thanks for the reply. I gave your suggestion a try and got 'Invalid Use of
Null" error message. I placed the line below into the UpperTolerance
AfterUpdate event. Or would it be better in the hidden field
(SignificantDigits) event of some type?

SignificantDigits.Value = Int([UpperTolerance]) & "." &
Left([UpperTolerance] - Int([UpperTolerance]) & "000",
SignificantDigits.Value)

Thanks.
John

KARL DEWEY said:
The Nz function returns a 'number' and numbers do not have leading zeros or
trailing decimal zeros. A text field can display both leading and trailing
zeros.

UNTESTED - But I think you can use the hidden field value like this --

Int([UpperTolerance]) & "." & Left([UpperTolerance] -
Int([UpperTolerance]) & "000", SignificantDigits.Value)

--
Build a little, test a little.

:

I have an engineering tolerance test result that needs to be kept as a
decimal but the field is dropping the last zero entered. An example is if
the user types in 0.010, the last 0 is getting dropped. That 0 must be
there. (In engineering tolerance testing of med devices there is a
difference between .010 and .01.)

There is another field (hidden) that is to store the number of places after
the decimal point. So in the example above it should have 3 in the hidden
textbox. The code below is in the AfterUpdate event of the tolerance field
the user would enter the 0.010 but the hidden field will show 2 instead of 3.
If the user typed in 0.001, the hidden field shows 3, which is correct.
Mainly, if the last digit typed is 0, then it drops off and the count in the
hidden field is short by one.

Dim decCount As Long
decCount = Nz(Len(Mid([UpperTolerance], InStr([UpperTolerance], ".") + 1)), 0)
SignificantDigits.Value = decCount

Am I missing something in the code above that would count the ending 0? I
tried this in the BeforeUpdate of the tolerance field and got the same
result. I need help on this.

Thanks.

John