错误捕捉了:)function isexists(aaa as control) as boolean
   dim tmp as string 
   aaa=true
   on error goto err1
   tmp=aaa.name
   exit sub
err1:
   aaa=false
end function

解决方案 »

  1.   

    function isexists(aaa as control) as boolean
       dim tmp as string 
       isexists=true
       on error goto err1
       tmp=aaa.name
       exit sub
    err1:
       isexists=false
    end function
      

  2.   

    If obj Is Nothing Then
        MsgBox "obj 不存在"
    End If
      

  3.   

    agree with gump2000(阿甘) 
    错误捕捉了:)
      

  4.   

    to: lihonggen0(用VB)  & Chimae(齐藤) 使用该方法是行不通的,请做测试。例子代码:判断控件(特别是控件数组)是否存在(
    http://www.csdn.net/Expert/TopicView1.asp?id=574473Private Sub Command1_Click()
            
            MsgBox DoesControlExist(Option1(1))
            
    End Sub
    Private Function DoesControlExist(ByRef ctl As Control) As Boolean
            
    On Error GoTo handleError        DoesControlExist = (ctl.Name <> vbNullString)
            Exit Function
            
    handleError:
            DoesControlExist = False
            
    End Function
      

  5.   

    Function isexists(aaa As Control) As Boolean
       Dim tmp As String
       isexists = True
       On Error GoTo err1
       tmp = aaa.Name
       Exit Function
    err1:
       isexists = False
    End FunctionPrivate Sub Command4_Click()
        MsgBox isexists(Option1(1))
    End Sub还可以啊:)
      

  6.   

    to:rushing(勇敢的心) 利用历遍所有控件,判断名字和Index(如果是控件数组),这个方法是可以的,不过,时间上,比利用错误捕捉来直接判断,要稍差点。而且,利用错误捕捉,通过测试,是可行的!