CodeItBetter Programming Another VB Programming Blog

How to return the smallest parameter value.

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'Math - How to return the smallest parameter value.
Option Explicit
 
Private Function Min(ParamArray values() As Variant) As Variant
    Dim i As Integer
    Dim min_value As Variant
 
    min_value = values(LBound(values))
    For i = LBound(values) + 1 To UBound(values)
        If min_value > values(i) Then min_value = values(i)
    Next i
 
    Min = min_value
End Function
 
'Call this function as:
'    txtMin.Text = Format$(Min(CInt(txtValue1.Text), CInt(txtValue2.Text), CInt(txtValue3.Text), _
'    CInt(txtValue4.Text), CInt(txtValue5.Text), CInt(txtValue6.Text), CInt(txtValue7.Text), _
'    CInt(txtValue8.Text)))
Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.