Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
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-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated