用ParamArray接收任意个参数

发表于:2007-06-17来源:作者:点击数: 标签:
Use ParamArray to Accept an Arbitrary Number of Parameters Submitted by Michael C. Amundsen, mike_tips@amundsen.com, http://www.amundsen.com You can use the ParamArray keyword in the declaration line of a method to create a subroutine or f

   
  Use ParamArray to Aclearcase/" target="_blank" >ccept an Arbitrary Number of Parameters
Submitted by Michael C. Amundsen, mike_tips@amundsen.com, http://www.amundsen.com

You can use the ParamArray keyword in the declaration line of a method to create a subroutine or function that accepts an arbitrary number of parameters at runtime. For example, you can create a method that will fill a list box with some number of items even if you do not know the number of items you will be sent. Add the method below to a form:

Public Sub FillList(ListControl As ListBox, ParamArray Items())
    注释:
    Dim i As Variant
    注释:
    With ListControl
        .Clear
        For Each i In Items
            .AddItem i
        Next
    End With
    注释:
End Sub

Note that the ParamArray keyword comes BEFORE the parameter in the declaration line. Now add a list box to your form and a command button. Add the code below in the "Click" event of the command button.

Private Sub Command1_Click()
    注释:
    FillList List1, "TiffanyT", "MikeS", "RochesterNY"
    注释:
End Sub

原文转自:http://www.ltesting.net