I have written the following simple function to determine the 'Best' score of three attempts. The number can range from -30 to +30 or so and are measured to 0.5 intervals.
This function works perfectly when running it in a query with no hassles what so ever.
But
When i try and run it as an 'AfterUpdate' or 'OnCurrent' event on a form there is some funny rounding going on.
eg three values of -1, 3, and 5.5 will return as a 6 rather than a 5.5 while three values of -1, 3, 5 will always return as 5.
I have noticed in the vb section of the form when i try to write the function for some reason the variables are being changed from doubles to longs. I beleive this is probably the source of my problem but i can't work out how to fix it.
eg when i try this:
The autoprompt thing kicks in and starts this
I can't work out why the variable appear to be changed from double to long, given the function is located in a functions module.
All help welcome and very much appreciated.
Cheers
Nathan
Code:
Function FlexBest(a As Double, b As Double, c As Double) As Double
If CDec(Nz(a)) >= CDec(Nz(b)) And CDec(Nz(a)) >= CDec(Nz(c)) Then
FlexBest = CDec(Nz(a))
ElseIf CDec(Nz(b)) >= CDec(Nz(a)) And CDec(Nz(b)) >= CDec(Nz(c)) Then
FlexBest = CDec(Nz(b))
Else
FlexBest = CDec(Nz(c))
End If
This function works perfectly when running it in a query with no hassles what so ever.
But
When i try and run it as an 'AfterUpdate' or 'OnCurrent' event on a form there is some funny rounding going on.
eg three values of -1, 3, and 5.5 will return as a 6 rather than a 5.5 while three values of -1, 3, 5 will always return as 5.
I have noticed in the vb section of the form when i try to write the function for some reason the variables are being changed from doubles to longs. I beleive this is probably the source of my problem but i can't work out how to fix it.
eg when i try this:
Code:
txtBest = FlexBest([txtFlexOne], [txtFlexTwo], [txtFlexThree])
The autoprompt thing kicks in and starts this
Code:
[I]txtBest = FlexBest(a As Long, b As Long, c As Long) As Long[/I]
I can't work out why the variable appear to be changed from double to long, given the function is located in a functions module.
All help welcome and very much appreciated.
Cheers
Nathan