在MS Outlook VBA中,表格对象的结构如何使行计数不可靠?

huangapple go评论64阅读模式
英文:

In MS Outlook VBA, how does the structure of a Table object make a row count unreliable?

问题

Table object没有count属性。相反,它有一个名为GetRowCount的方法。但要注意,该方法不可靠,可能返回近似计数并导致错误。

有没有人知道,Table对象的结构有何不同,导致VBA无法知道其计数?

英文:

The Table object does not have a property count. Instead, it has the method GetRowCount. But that comes with the warning that it's not reliable and may return an approximate count and yield an error.

Does anyone here know what's different about the structure of a Table object that prevents VBA from knowing its count?

答案1

得分: 1

以下是翻译好的部分:

"GetRowCount" 方法对应于 IMAPITable::GetRowCount 方法,该方法解释了可能的原因,如内存限制等。您可能会发现以下描述有帮助:

使用 "GetRowCount" 来了解在调用 "IMAPITable::QueryRows" 方法检索数据之前表格中包含多少行。如果表格中少于二十行,则可以安全地调用 "QueryPosition" 来检索整个表格。如果表格中的行数超过二十行,则考虑多次调用 "QueryPosition" 并限制每次检索的行数。

有些表格不支持 "GetRowCount" 并返回 MAPI_E_NO_SUPPORT。如果不支持 "GetRowCount",一个替代方法可能是调用 "IMAPITable::QueryPosition"。使用 "QueryPosition" 的结果,您可以确定当前行与最后一行之间的关系。

当 "GetRowCount" 返回 MAPI_E_BUSY,因为它暂时无法检索行数时,请调用 "IMAPITable::WaitForCompletion" 方法。当 "WaitForCompletion" 返回时,请重试调用 "GetRowCount"。检测异步操作是否正在进行的另一种方法是调用 "IMAPITable::GetStatus" 方法并检查 "lpulTableState" 参数的内容。

在 "Extended MAPI"(Outlook 基于的低级 API)中,您可以使用 IMAPITable::QueryRows 方法指定要获取多少行。

英文:

The GetRowCount method corresponds to the IMAPITable::GetRowCount method which explains possible reasons like memory constraints and etc. You may find the following description helpful:

> Use GetRowCount to find out how many rows a table holds before making a call to the IMAPITable::QueryRows method to retrieve the data. If there are less than twenty rows in the table, it is safe to call QueryPosition to retrieve the whole table. If there are more than twenty rows in the table, consider making multiple calls to QueryPosition and limit the number of rows retrieved in each call.

> Some tables do not support GetRowCount and return MAPI_E_NO_SUPPORT. If GetRowCount is not supported, an alternative might be to call IMAPITable::QueryPosition. With the results from QueryPosition, you can determine the relationship between the current row and last row.

> When GetRowCount returns MAPI_E_BUSY because it is temporarily unable to retrieve a row count, call the IMAPITable::WaitForCompletion method. When WaitForCompletion returns, retry the call to GetRowCount. Another way to detect whether an asynchronous operation is in progress is to call the IMAPITable::GetStatus method and check the contents of the lpulTableState parameter.

In Extended MAPI (a low-level API on which Outlook is based on) you can specify how many rows you would like to get using the IMAPITable::QueryRows method.

答案2

得分: 1

以下是翻译好的部分:

有些表格(比如大型的GAL或LDAP通讯录提供者表格)不知道它们有多少行,你能做的最好的事情就是搜索特定的条目或逐个枚举行(这是一个不好的主意)。

这通常不适用于文件夹内容表格 - 你总是可以获取计数。但在循环遍历集合时,行数可能会随时更改,所以最好在循环遍历项时使用Items.Find/FindNext/Restrict或使用枚举器(如果你绝对必须这样做)。

英文:

Some tables (such as large GAL or LDAP address book provider tables) do not know how many rows they have, the best you can do is either search for a particular entry or enumerate the rows one at a time (which is a bad idea).

This usually does not apply to the folder contents tables - you can always get the count. But the row count can always change while you are looping through the collection, so it is always better to use Items.Find/FindNext/Restrict or use am enumerator when looping through the items (if you absolutely have to).

huangapple
  • 本文由 发表于 2023年5月24日 23:14:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325046.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定