“内存不足” VBA 中的 Lotus Notes 自动化错误
此 VBA 函数偶尔会失败,并出现 Notes 自动化错误“运行时错误 '7' 内存不足”。当然,当我尝试手动重现它时,一切都运行良好。
Function ToGMT(ByVal X As Date) As Date
Static NtSession As NotesSession
If NtSession Is Nothing Then
Set NtSession = New NotesSession
NtSession.Initialize
End If
(do stuff)
End function
为了说明这一点,此 VBA 函数由 Access 查询调用,每条记录调用 3-4 次,有 20,000 条记录。出于性能原因,NotesSession 已设为静态。知道为什么它偶尔会出现内存不足错误吗?
(另外,我启动 NotesSession 只是为了使用 Lotus 规则将日期时间转换为 GMT。如果您知道更好的方法,我会倾听)。
编辑
根据罗斯先生的问题,我隔离了(或认为我隔离了)查询及其支持功能。在尝试您的建议之前,我首先添加了一些参数来确定哪一行和哪一行。它坠毁的领域。我运行了几次,它在第一行的第一个字段崩溃了。
然后急!一切顺利。所以我试图回溯看看我做了什么。找不到任何东西。我什至回到了原来的查询,它一直失败,发现一切都运行良好,即使没有任何改变(或者我认为是这样)。
所以,我无法尝试你的建议,但我仍然学到了一些东西。这真让我烦恼。此功能是否会与其他 Notes 进程冲突?
(另一件事。这不可能是硬件/内存问题。这台机器是双核,具有 2GB RAM。)
编辑 #2
这确实占用了我太多时间。我决定对日期进行硬编码。罗斯先生,您的链接看起来是一个可靠的、功能齐全的功能,但我没有时间再检查逻辑了。这是我的做法:(它的效果比我想象的要好。我预计会有更多差异)
Function ToGMT(ByVal X As Date) As Date
'Ugly? Yes. A cheap hack? Yes.
'But this method is fast and verifiable. So let's go with it.
'Of course, if you're reading this in the year 2016, well,
'you should be able to figure out what to do.
If X >= #4/2/2006 1:00:00 AM# And X <= #10/29/2006 3:00:00 AM# Or _
X >= #3/11/2007 1:00:00 AM# And X <= #11/4/2007 3:00:00 AM# Or _
X >= #3/9/2008 1:00:00 AM# And X <= #11/2/2008 3:00:00 AM# Or _
X >= #3/8/2009 1:00:00 AM# And X <= #11/1/2009 3:00:00 AM# Or _
X >= #3/14/2010 1:00:00 AM# And X <= #11/7/2010 3:00:00 AM# Or _
X >= #3/13/2011 1:00:00 AM# And X <= #11/6/2011 3:00:00 AM# Or _
X >= #3/11/2012 1:00:00 AM# And X <= #11/4/2012 3:00:00 AM# Or _
X >= #3/10/2013 1:00:00 AM# And X <= #11/3/2013 3:00:00 AM# Or _
X >= #3/9/2014 1:00:00 AM# And X <= #11/2/2014 3:00:00 AM# Or _
X >= #3/8/2015 1:00:00 AM# And X <= #11/1/2015 3:00:00 AM# Then
ToGMT = DateAdd("h", -1, X)
Else
ToGMT = X
End If
End Function
This VBA function sporadically fails with a Notes automation error "Run-Time Error '7' Out of Memory". Naturally, when I try to manually reproduce it, everything runs fine.
Function ToGMT(ByVal X As Date) As Date
Static NtSession As NotesSession
If NtSession Is Nothing Then
Set NtSession = New NotesSession
NtSession.Initialize
End If
(do stuff)
End function
To put this in context, this VBA function is being called by an Access query, 3-4 times per record, with 20,000 records. For performance reasons, the NotesSession has been made static. Any ideas why it is sporadically giving an out-of-memory error?
(Also, I'm initiating the NotesSession just so I can convert a datetime to GMT using Lotus's rules. If you know a better way, I'm listening).
Edit
Per Mr. Ross's question, I isolated (or thought I did) the query and it's supporting function. Before I tried your suggestion, I added some arguments first to determine which row & field it crashed on. I ran it a few times and it crashed on the first field of the first row.
Then presto! Everything ran fine. So I tried to backtrack to see what I did. Couldn't find anything. I even went back to the original query where it was failing consistently and found that everything ran fine even though nothing had changed (or so I think).
So, I couldn't try your suggestion, but I still learned something. This is really annoying me. Could this function be conflicting with some other Notes process?
(1 other thing. It can't be a hardware/memory issue. This machine is a dual core with 2gb RAM.)
Edit #2
This is really taking up too much of my time. I've decided to just hardcode the dates. Mr. Ross, your link looks like a solid, full-featured function, but I haven't the time anymore to check the logic. Here's what I went with instead: (it works better than I thought for my purposes. I was expecting more discrepancies)
Function ToGMT(ByVal X As Date) As Date
'Ugly? Yes. A cheap hack? Yes.
'But this method is fast and verifiable. So let's go with it.
'Of course, if you're reading this in the year 2016, well,
'you should be able to figure out what to do.
If X >= #4/2/2006 1:00:00 AM# And X <= #10/29/2006 3:00:00 AM# Or _
X >= #3/11/2007 1:00:00 AM# And X <= #11/4/2007 3:00:00 AM# Or _
X >= #3/9/2008 1:00:00 AM# And X <= #11/2/2008 3:00:00 AM# Or _
X >= #3/8/2009 1:00:00 AM# And X <= #11/1/2009 3:00:00 AM# Or _
X >= #3/14/2010 1:00:00 AM# And X <= #11/7/2010 3:00:00 AM# Or _
X >= #3/13/2011 1:00:00 AM# And X <= #11/6/2011 3:00:00 AM# Or _
X >= #3/11/2012 1:00:00 AM# And X <= #11/4/2012 3:00:00 AM# Or _
X >= #3/10/2013 1:00:00 AM# And X <= #11/3/2013 3:00:00 AM# Or _
X >= #3/9/2014 1:00:00 AM# And X <= #11/2/2014 3:00:00 AM# Or _
X >= #3/8/2015 1:00:00 AM# And X <= #11/1/2015 3:00:00 AM# Then
ToGMT = DateAdd("h", -1, X)
Else
ToGMT = X
End If
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将 NtSession 从静态更改为在每次调用函数时设置,然后在函数结束时设置为空时,会发生什么?
我知道这会损害性能,但试一试,看看会发生什么,然后回发
编辑:
您关于转换为 GMT 的评论让我思考,这个功能有什么好处吗?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=第813章
What happens when you change it NtSession from being a static to being setup on each call to the function and then set to nothing at the end of the function?
I know it will hurt performance but give it a shot and see what happens and post back
EDIT:
Your comment about converting to GMT got me thinking, would this funciton be of any good?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=813