在你的工程中添加一个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测试通过,你试试吧
呵呵,不是我要這樣認為啊,,,,是我這邊的情況就是這樣的嘛. 我把代碼貼出來,幫我看看是代碼的問題還是其它原因? '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"
你说我的第一次的回复代码不能运行,你就在瞎说啊在你的工程中添加一个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中加入代码
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测试通过,你试试吧
^_^
[email protected] 謝謝了!快點啊~~~
但是"ldmsapp"是不是Winrar壓縮文件?我怎麼解壓縮不了啊?555555555
可能是操作系統的原因吧,我的是Win2k.其它都是一樣的VB英文+SP5.唉,,郁悶啊!!!!!
這種方法也試過,也不行的.Function應該不能返回自定義類型的值.
另外我用(Optional Byref 參數 as 自定義類型),傳給這個Function.同樣也是不支持自定義類型.
我把代碼貼出來,幫我看看是代碼的問題還是其它原因?
'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"
你的原来的问题已经解决了
你现在的意思和你的原来问题根本是两回事
增加之后你有两个工程在视图中在控件工程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
有兩個工程,那麼UserControl是在哪個工程呢?
能不能再詳細點?~~