本帖最后由 yxcsniper 于 2010-07-20 11:14:08 编辑

解决方案 »

  1.   

    大家看下Case 5的代码,就是这段,前面和后面都有color的
      

  2.   

    1楼的试试Public Function GetAttr(Keyss As String, Optional CName, Optional Units As Integer) '取出UDA的值          Set attr = Uda_Collection.Item(Keyss)
                  
                   Select Case attr.ExtentionContentType
                      
                      Case 0
                         GetAttr = attr.IntVal
                      
                      Case 1
                         GetAttr = attr.DoubleVal
                      
                      Case 2
                         If attr.BoolVal = True Then
                            GetAttr = 1
                         Else
                            GetAttr = 0
                         End If
                      
                      Case 3
                         GetAttr = attr.StrVal
                         
                      Case 4
                         GetAttr = attr.Date
                         
                      Case 5
                         If Not IsEmpty(CName) Then
                            EnumStrings = attr.EnumStrings
                            
                            For j = 0 To UBound(EnumStrings)
                              EnumString = EnumStrings(j)
                              CName.List(j) = EnumString
                            Next j
                            
                            GetAttr = attr.StrVal
                         End If
                      
                      Case 6
                         GetAttr = Format(attr.Length(Units), "##########0.0##")
                         
                      Case 7
                         GetAttr = Format(attr.Area(Units), "##########0.0##")
                         
                      Case 8
                         GetAttr = Format(attr.Weight(Units), "##########0.0##")
                         
                  End Select
                  
    End Function
      

  3.   

    不行啊
    1楼和3楼的方法是一样的
    我试过了
    当我执行如GetAttr("xxxxx")
    后面的参数"Cname"不填写时,
    总是报错“运行时错误424,需要对象”
      

  4.   

    //If Not IsEmpty(CName) Thenif not isnothing(Cname) then
      

  5.   

    两个参数颠倒一下
    Public Function GetAttr(Keyss As String, Optional Units As Integer, Optional CName)
      

  6.   

    一般来说,会给可选参数赋缺省值来进行区分,
    例如:Public Function GetAttr(Keyss As String, Optional CName as ComboBox = nothing, Optional Units As Integer = 0)或者可以试试使用函数IsMissing来判断。
      

  7.   

    谢谢!我用IsMissing函数判断成功了!
    也非常感谢前面的几位兄弟的回答!