using keyPress event to change field value and Fraction eval funct

R

rolaaus

I saw the following code segment in reference to changing a field value
depending on whether + or - was pressed.

Select Case KeyAscii
Case 43 ' Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1
Case 45 ' Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - 1
End Select

My question is I have a field that may or may not have fractions, and I want
the + or - to change the fraction only. Is there a function or some way to
evaluate the fraction portion of the value of a field?

I will probably have to end up using a select case to determine what the
fraction is, then use the above code to change the fraction up or down, but I
don't know how to determine if the field has a fraction.

select case fraction(me.txtFieldName)
case .25
Select Case KeyAscii
Case 43 ' Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + .25
Case 45 ' Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - .25
End Select
end select
 
R

rolaaus

I'm not sure about design spec's - I just went through a VB.net programming
class @ DeVry, but we skipped over that. I figure we would be getting to it
in further classes. Anyways, my main question was concerning some function
for getting the fraction portion of a variable.

If x = 1.5
I want y to equal .5

if x = 3.75
I want y to equal .75

Everything else I can pretty much handle, but I posted it to see if there
were any further suggestions, like giving the decimals some sort of "class"
properties so that the program automatically knows what I want when the
variable is .75 and the - button is pressed, I want the variable to change to
..5
 
D

Douglas J. Steele

The fractional part will be MyValue - Int(MyValue) for positive values of
MyValue
 
B

Bas Cost Budde

rolaaus said:
My question is I have a field that may or may not have fractions, and I want
the + or - to change the fraction only. Is there a function or some way to
evaluate the fraction portion of the value of a field?

If I understand this correctly, your question is not complete.

If the fraction is .32, what will be your increment value? That is: how
are you going to decide what the step size is, on what do you want to
base this?

You have to make a fixed decision about the smallest step size. After
that, you can do a GCD algorithm to get at the actual step size to
apply: divide the actual fraction by the smallest step you've defined.
But even then, if the amount of steps in the fraction is, say, 6, are
you deciding you will multiply by 2 or 3?

Maybe it is best to define a small table with possible step sizes; you
can then take the fraction of the field, divide it by the step size in
the table (in a query, so for all records), do a little rounding to get
around floating point mistakes, and take the largest step size that
gives an integer result.
 

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