我想在控件裡寫一個Function,有什麼辦法能使這個Function能返回自定義類型的值?
分數不多^_^
靜候佳音!!!!謝閱

解决方案 »

  1.   

    在你的工程中添加一个ActiveX 控件的工程 ,注意是增加工程
    增加之后你有两个工程在视图中在控件工程2中加入代码
    Type MyRecord
       name As String
    End Type
    Function doit(ByVal par As Integer) As MyRecord
        Dim aa As MyRecord
        If par = 1 Then
            aa.name = "yes"
        Else
            aa.name = "no"
        End If
        doit = aa
    End Function然后关掉activX控件设计器,注意要关掉这个设计窗口,控件才能够可以使用
    关掉之后,工程1上的控件栏中你自己做的控件可以选择了,将它拖放到form1中
    缺省名字为UserControl11然后在form1的command1中加入代码
    Private Sub Command1_Click()
        MsgBox UserControl11.doit(1).Name
    End Sub测试通过,你试试吧
      

  2.   

    SoHo_Andy(冰) 這樣好像不行吧????開始我也是這樣寫的,但運行時會出錯,說不能返回自定義類型的值!!!!!!!!你真的 "测试通过"嗎????騙子
    ^_^
      

  3.   

    真的嗎?太好了!!!
    [email protected] 謝謝了!快點啊~~~
      

  4.   

    收到!
    但是"ldmsapp"是不是Winrar壓縮文件?我怎麼解壓縮不了啊?555555555
      

  5.   

    要安装Winrar3。0,到处都有下载
      

  6.   

    現在可以解開了,可打開Group時發生錯誤:"Out of Memory"?為什麼會這樣?
      

  7.   

    我這有安裝...
    可能是操作系統的原因吧,我的是Win2k.其它都是一樣的VB英文+SP5.唉,,郁悶啊!!!!!
      

  8.   

    To: aoenzh(独孤大虾) 
    這種方法也試過,也不行的.Function應該不能返回自定義類型的值.
    另外我用(Optional Byref 參數 as 自定義類型),傳給這個Function.同樣也是不支持自定義類型.
      

  9.   

    呵呵,function 能不能返回自定义类型变量的问题讨论过很多次了为什么你还要这样认为虽然不知道你的机子为什么不行,可是你可以到别人的机子上试啊
      

  10.   

    呵呵,不是我要這樣認為啊,,,,是我這邊的情況就是這樣的嘛.
    我把代碼貼出來,幫我看看是代碼的問題還是其它原因?
    'Module1:
    Public Type udRowOrCol
        udRow As Long
        udCol As Long
    End Type'UserControl:
    Public Function FindStr(ByVal strValue As String, Optional CompareType As VbCompareMethod = vbTextCompare) As udRowOrCol
        Dim I As Integer
        Dim J As Integer
        For I = 0 To Combo1.ListCount - 1
            For J = 0 To Combo1.ColumnCount - 1
                If StrComp(Combo1.List(I, J), strValue, CompareType) Then
                    FindStr.udCol = I
                    FindStr.udRow = J
                    Exit Function
                End If
            Next
        Next
    End Function'為什麼會出現以下錯誤呢????:
    "Private Enum and user-defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user-defined types"
      

  11.   

    公共函数和自定义的变量声明放在一起就可以使用"我想在控件裡寫一個Function,有什麼辦法能使這個Function能返回自定義類型的值"
    你的原来的问题已经解决了
    你现在的意思和你的原来问题根本是两回事
      

  12.   

    你说我的第一次的回复代码不能运行,你就在瞎说啊在你的工程中添加一个ActiveX 控件的工程 ,注意是增加工程
    增加之后你有两个工程在视图中在控件工程2中加入代码
    Type MyRecord
       name As String
    End Type
    Function doit(ByVal par As Integer) As MyRecord
        Dim aa As MyRecord
        If par = 1 Then
            aa.name = "yes"
        Else
            aa.name = "no"
        End If
        doit = aa
    End Function然后关掉activX控件设计器,注意要关掉这个设计窗口,控件才能够可以使用
    关掉之后,工程1上的控件栏中你自己做的控件可以选择了,将它拖放到form1中
    缺省名字为UserControl11然后在form1的command1中加入代码
    Private Sub Command1_Click()
        MsgBox UserControl11.doit(1).Name
    End Sub
      

  13.   

    不太明白....
    有兩個工程,那麼UserControl是在哪個工程呢?
    能不能再詳細點?~~