Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake functions that calculate the minimum and maximum of their parameters
DescriptionThis example shows how to make functions that calculate the minimum and maximum of their parameters in Visual Basic 6.
KeywordsMin, Max, minimum, maximum
CategoriesSoftware Engineering, Algorithms
 
The Min and Max functions take ParamArray parameters so you can use them with any number of arguments. These functions simply loop over the values passed to them looking for the smallest/largest.
 
' Return the smallest parameter value.
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
' Return the smallest parameter value.
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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated