I have four variables DHVN, DHVE, DHVS, and DHVW that are calculated in my code. Next, I need to do another calculation that involves picking the highest of these four variables. Can someone tell me how to do this?
I have four variables DHVN, DHVE, DHVS, and DHVW that are calculated in my code. Next, I need to do another calculation that involves picking the highest of these four variables. Can someone tell me how to do this?
the most direct way is compare them one by one then pick the max one.
These would work with variables as well as fields:
http://support.microsoft.com/default...b;en-us;209857
Thanks pbaldy but I cannot view the link you sent me.
Not sure why not; it's a normal Microsoft KB page. Here's the function from it:
Called like:Code:Function Maximum(ParamArray FieldArray() As Variant) ' Declare the two local variables. Dim I As Integer Dim currentVal As Variant ' Set the variable currentVal equal to the array of values. currentVal = FieldArray(0) ' Cycle through each value from the row to find the largest. For I = 0 To UBound(FieldArray) If FieldArray(I) > currentVal Then currentVal = FieldArray(I) End If Next I ' Return the maximum value found. Maximum = currentVal End Function
Maximum(DHVN, DHVE, DHVS, DHVW)
After I call the function i.e.
Call Maximum(DHVN, DHVS, DHVE, DHVW)
I am using the variable created in the function, Maximum, for the next calculation. It is giving me an error reading:
"The value you entered isn't valid for this field.
For example, you may have entered text in a numeric field ot a number that is larger than the FieldSize setting permits."
It would help to see your actual code, and what the variables might contain. I'd expect:
SomeNewVariable = Maximum(DHVN, DHVS, DHVE, DHVW)
My code is the folowing:
...
S = DHVN * F * O
T = DHVE * G * P
U = DHVS * H * Q
V = DHVW * II * R
W = Abs(S + T + U + V)
If E = N Then
XX = "Bad Parity"
Dim Max As Double
Max = Maximum(DHVN, DHVS, DHVE, DHVW)
If W < (Max / 2) Then
XX = "Factors are Valid"
End If
If XX = "" Then
XX = "Factors are Valid"
End If
What line throws the error? That code shouldn't even compile, as this bit:
If E = N Then
XX = "Bad Parity"
doesn't have the required "End If".