vb function的返回类型是否不能为object?
自定义函数
Private Function GetObj() as Object
Dim tessObj As New cTest 'cTest是自定义的一个类
tessObj.A = "a"
testObj.B= "b"
GetObj=tessObj
End Function
调用:
Dim testGetObj as Object
testGetObj=GetObj()
出现错误:
Run-time error'91':
object variable or with block variable not set
[解决办法]
上面有误,改成下面:
- VB code
Option Explicit'自定义函数Private Function GetObj() As Object Dim testObj As New CTest 'cTest是自定义的一个类 testObj.A = "a" testObj.B = "b" Debug.Print "1", testObj.A, testObj.B Set GetObj = New CTest GetObj.A = testObj.A GetObj.B = testObj.B Debug.Print "2", GetObj.A, GetObj.BEnd FunctionPrivate Sub Command1_Click() Dim testGetObj As Object 'On Error Resume Next Set testGetObj = New CTest testGetObj.A = GetObj.A testGetObj.B = GetObj.B Debug.Print "3", testGetObj.A, testGetObj.BEnd Sub
[解决办法]
改用Load语句试试?