NotesDocument 作为函数返回值的问题

 'some code ......
'Set my doc with the return value from the function...
Set recipientDoc = getDocInNAB("search string")

If Not recipientDoc Is Nothing Then
'In debug I end up here
Else
'When I run it I end up here....
Print "ERROR"
End If
'some code ......

Function getDocInNAB(y As String) As NotesDocument
Dim nabs As Variant
Dim v As NotesView
Dim match As NotesDocument
Dim i As NotesItem
nabs = s.AddressBooks

Forall x In nabs
'Get handle on Directory to search
Call x.Open(x.Server, x.FilePath)
Set v = x.GetView("($Users)")
Set match = v.GetDocumentByKey(y,True)

If Not match Is Nothing Then
Print "Found ------------> " & y
Set getDocInNAB = match
Else
Set getDocInNAB = Nothing
End If
End Forall
End Function

函数 getDocInNAB 实现了一个功能:通过参数 y 来查找个人文档,然后将查找结果返回。初看上去好像没什么问题,实际上这个函数的返回值一直是 Nothing。

问题的原因是,NAB 数据库对象是在函数内定义的,当文档作为返回值传递给调用者时,其 Parent 数据库对象已经销毁,所以这个文档也就是 Nothing 了。

解决的办法:将数据库一起作为参数传递过去或者定义为全局变量。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值