“内存不足"; VBA在Lotus Notes自动化中出现错误 [英] "Out of Memory" error in Lotus Notes automation from VBA

查看:146
本文介绍了“内存不足"; 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

为了说明这一点,Access查询正在调用此VBA函数,每条记录3-4次,有20,000条记录.出于性能原因,NotesSession已设置为静态.知道为什么它偶尔会出现内存不足错误吗?

(此外,我正在启动NotesSession,以便可以使用Lotus的规则将日期时间转换为GMT.如果您知道更好的方法,我在听).

编辑

根据罗斯先生的问题,我隔离(或认为我做了)查询及其支持功能.在尝试您的建议之前,我先添加了一些参数来确定哪一行&崩溃了.我运行了几次,它在第一行的第一个字段上崩溃了.

然后保存!一切都很好.所以我试图回溯看看我做了什么.找不到任何东西.我什至回到了始终失败的原始查询,发现即使没有任何更改(或我认为),一切都可以正常运行.

因此,我无法尝试您的建议,但我仍然学到了一些东西.这真让我讨厌.此功能可能会与其他某些Notes进程冲突吗?

(还有1件事.这不可能是硬件/内存问题.这台机器是具有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

解决方案

将NtSession从静态更改为在每次调用函数时都进行设置,然后在函数末尾设置为空时会发生什么? /p>

我知道它会影响性能,但请试一试,看看会发生什么并发回

您对转换为格林尼治标准时间的评论让我开始思考,这个功能有什么好处吗?

http://www.vbaexpress.com/kb/getarticle.php ?kb_id = 813

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

解决方案

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

这篇关于“内存不足"; VBA在Lotus Notes自动化中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆