VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 用ParamArray接收任意个参数
发表评论(0)作者:Michael C. Amundsen, 平台:VB6.0+Win98, 阅读:8833, 日期:2000-10-30
Use ParamArray to Accept an Arbitrary Number of Parameters

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