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
 
 
 
 
 
TitleUse the ParamArray keyword to make a routine that takes a variable number of arguments
KeywordsParamArray
CategoriesSoftware Engineering, Tips and Tricks
 
Use the ParamArray keyword. The parameter should be an array of Variants. Use LBound and UBound to see how many arguments are in the parameter array.

This example uses ParamArray to make an Average function that returns the average of any number of values.

 
Private Function Average(ParamArray arguments() As Variant) _
    As Single
Dim i As Integer
Dim total As Single

    For i = LBound(arguments) To UBound(arguments)
        total = total + arguments(i)
    Next i
    Average = total / (UBound(arguments) - _
        LBound(arguments) + 1)
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated