我写一function需要用户传两个或三个参数
用户用下面两种调用方法都可以:
addorg(id,treeview,listview)
addorg(id,treeview)怎么写这个addorg呢?

解决方案 »

  1.   

    Try
    public function addory(id as integer, byref listview as variant)
    end function
      

  2.   

    AddOrg( ID,Treeview,Option ListView)  
     if isobject(listView) then  else endif
      

  3.   

    可以用Option 选项来设定参数,用Option 设定的参数是可选参数.
      

  4.   

    Public Function addorg(Optional ByVal id As String, Optional ByVal treeview As String, Optional ByVal listview As String)
    '代码
    End Function
      

  5.   

    Public Function  addorg(id,treeview,Optional listview)
      

  6.   

    Public Function addorg(id, treeview As Object, Optional listview1 As Object) If TypeOf listview1 Is listview Then endifend function
      

  7.   

    Public Function addorg(id,tvwObject As Object, Optional lvwObject As Object)
        If Not IsMissing(lvwObject) Then
           '假如lvwObject已经传入,则执行该段代码
        Else
           '假如lvwObject未传入,则执行该段代码
        End If
    End Function
      

  8.   

    我用的是
        if not (lvwobject is nothing) then
     
        end if也可以吧?
      

  9.   


       把第三个参数声明为option就OK!
      

  10.   

    使用 IsMissing 来判断是否传了参数
      

  11.   

    Function addorg(Byval id as integer,ParamArray objSource())
       Dim intCount                     As Integer
       Dim i                            As Integer
       
       On Error Resume Next
       '// 取得传入的参数的个数
       intCount = UBound(objSource)
       
       For i = 0 To intCount
          Select Case TypeName(objSource(i))
             Case "什么类型"
                '做什么事      End Select
       Next
    End Function