How to return the biggest parameter value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'Math - How to return the biggest parameter value.
Option Explicit
 
Private Function Max(ParamArray values() As Variant) As Variant
    Dim i As Integer
    Dim max_value As Variant
 
    max_value = values(LBound(values))
    For i = LBound(values) + 1 To UBound(values)
        If max_value < values(i) Then max_value = values(i)
    Next i
 
    Max = max_value
End Function
 
'Call this function as:
'    txtMax.Text = Format$(Max(CInt(txtValue1.Text), CInt(txtValue2.Text), CInt(txtValue3.Text), _
'    CInt(txtValue4.Text), CInt(txtValue5.Text), CInt(txtValue6.Text), CInt(txtValue7.Text), _
'    CInt(txtValue8.Text)))

Tags: , , , , , , , , , , , , ,

Leave a Reply