问题:如何得知一个控件属于哪个类别?用TypeName函数。

解决方案 »

  1.   

    从没做过这类东西,不过我想如果你把SET去掉试试可不可以呀
      

  2.   

    这样:
    '-------------------
    ' class1.cls
    '-------------------
    Private varMSHFGrid As ObjectPublic Property Let GridSource(vNewValue As Object)
        If TypeName(vNewValue) = "MSHFlexGrid" Then
            Set varMSHFGrid = vNewValue
            Debug.Print "OK"
        Else
            MsgBox "对象赋值错误!", vbCritical + vbOKOnly
        End If
    End PropertyPublic Property Set GridSource2(vNewValue As Object)
        If TypeName(vNewValue) = "MSHFlexGrid" Then
            Set varMSHFGrid = vNewValue
            Debug.Print "OK"
        Else
            MsgBox "对象赋值错误!", vbCritical + vbOKOnly
        End If
    End Property
    '----------------------
    ' form1.frm
    '----------------------
    Private Sub Command1_Click()
        Dim objGrid As New Class1    ' 使用Let属性
        objGrid.GridSource = MSHFlexGrid1    ' or 使用Set属性
        Set objGrid.GridSource2 = MSHFlexGrid1    Set objGrid = Nothing
    End Sub
      

  3.   

    得知一个控件属于哪个类别,建议你不用此法,
    可以用 typeof 
    If TypeOf ctlText Is datagrid Then定义对象object和属性property是好的方法,是代码重用和面向对象的思想的结合
      

  4.   

    要监测控件的类型,可以用TypeName(),它的返回值是String
    dim myType as String 
    myType=TypeName(Text1)得到:myType="TextBox"类我也是刚用:Private m_vNewValue as ObjectProperty Let GridSource_数据源(ByVal newValue As Object)
       if newValue="" then Err.Raise 5
       m_vNewValue=newValue
    End Property
    这只是只写属性,只读要用Property Get Let GridSource_数据源()Private Sub Command1_Click()
    Dim a As clsa
    set a= New clsa
    a.GridSource_数据源 = MSHFlexGrid1
    a = Nothing
    End Sub这样可以吧,你试一下好了后,要给我分
      

  5.   

    对象属性建议用Property Set
      

  6.   

    If TypeOf objectname Is objecttype Then
    End If
      

  7.   

    agree to : hedane(hedane)
    仔细看看类模块的帮助
      

  8.   

    '类模块 clsa
    Private MvarGrid As Object '表格名称
    Public Property Let GridSource_数据源(vNewValue As Object)
    '问题:如何得知一个控件属于哪个类别?
        Set MvarGrid = vNewValue
    End Property错误的原因在与上面第三行应为:
    Public Property Set GridSource_数据源(vNewValue As Object)
    '问题:如何得知一个控件属于哪个类别?
        Set MvarGrid = vNewValue
    End Property