Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'A generic function to get the min value of an arbirtrary numbers of same type values:
Public Function MyMin(ParamArray Args())
Dim i As Long, rv
If UBound(Args) >= 0 Then rv = Args(LBound(Args))
For i = 1 + LBound(Args) To UBound(Args)
If IsNull(rv) Or rv > Args(i) Then rv = Args(i)
Next
MyMin = rv
End Function
sumoalex said:"I'm not sure that your code ... is appropriate ... "
'[b]Sample Usage:[/b]
'? basMinVal(1, 5, 9, 3, 13.663)
'1
[b][u][i]'? basMinVal(1, 5, Null, 9, 3, Null, 13.663)
'[COLOR=red]1[/color][/i][/u][/b]
PHV said:" ... just signaled you that your function was buggy ... "
Public Function basMinVal(varValTyp As String, ParamArray varMyVals() As Variant) As Variant
'Michael Red 10/25/2001
'To return the MINIMUM or a series of values _
excluding NULL - - - added 5/6/05
'Sample Usage:
'? basMinVal("sgl", 1, 5, 9, 3, 13.663)
'1
'? basMinVal("sgl", 1, 5, Null, 9, 3, Null, 13.663)
'1
'?basMinVal("int", 9, 1, 5, 3, 13)
'1
Dim Idx As Integer
Dim MyMin As Variant
Dim varBigVal As Variant
Select Case LCase(varValTyp)
Case Is = "byt"
varBigVal = 255
Case Is = "int"
varBigVal = 32767
Case Is = "lng"
varBigVal = 2147483647
Case Is = "sgl"
varBigVal = 3.4E+38
Case Is = "dbl"
varBigVal = 1.797E+308
Case Is = "txt"
varBigVal = String(255, "z")
End Select
If (UBound(varMyVals) < 0) Then
Exit Function
Else
MyMin = Nz(varMyVals(0), varBigVal)
End If
For Idx = 0 To UBound(varMyVals())
If (Not IsNull(varMyVals(Idx))) Then
If (varMyVals(Idx) < MyMin) Then
MyMin = varMyVals(Idx)
End If
End If
Next Idx
basMinVal = MyMin
End Function
Public Function Coalesce(ParamArray Vals())
Dim n As Long
Coalesce = Null
For n = LBound(Vals) To UBound(Vals)
If Not IsNull(Vals(n)) Then
Coalesce = Vals(n)
Exit Function
End If
Next
End Function