Sorry to follow up on myself, but did you get the point about how Dim
works in VBA (which is different from C, C#, VB.Net etc)?
Don't know about the "whew" but you're welcome. FWIW, here is the fully
generalised version:
myMaximumNumber = MaxOf(12, 4, 5, 25, 1)
'...
Public Function MaxOf(ParamArray Values() As Variant) As Integer
Dim i As Integer, l As Integer, u As Integer
Dim maxSoFar As Integer
Const vbErrInvalidProcedure As Long = 5
' remember these for later
l = LBound(Values)
u = UBound(Values)
' if there are no parameters, we don't want an out of bound errors:
' we'll raise an invalid procedure instead, much more meaningful
If l > u Then
' empty array
Err.Raise vbErrInvalidProcedure
Else
' VB does not provide anyway of type checking with a ParamArray
' so we have to do it on each parameter at a time
If VarType(Values(l)) <> vbInteger Then
Err.Raise vbErrInvalidProcedure
End If
' remember the first one
maxSoFar = Values(l)
' now go through the rest of them
For i = l + 1 To u
' ditto for type checking
If VarType(Values(i)) <> vbInteger Then
Err.Raise vbErrInvalidProcedure
End If
' then just remember the biggest one
If Values(i) > maxSoFar Then maxSoFar = Values(i)
Next i
' and return the value
MaxOf = maxSoFar
End If
End Function
Something to do with the evening, I guess... <g>
HTH
Tim F