热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

这些和函数之间的可靠性是否存在差异?-Isthereadifferenceinreliabilitybetweenthesesumfunctions?

SotheotherdayIwasgettingsomestrangesumvaluesandIwascompletelystumped.Igaveuponus

So the other day I was getting some strange sum values and I was completely stumped. I gave up on using a sum function in VBA and just added the values the long way (through loops), but then I read somewhere that using the sum functions in VBA isn't always reliable for developers? (I can't find the post anymore, but I'm still looking for it).

所以有一天我得到了一些奇怪的总和值,我完全被难倒了。我放弃在VBA中使用sum函数,只是添加了很长的值(通过循环),但后来我在某处读到使用VBA中的sum函数并不总是对开发人员可靠? (我找不到帖子了,但我还在找它)。

Is there any truth to this? I know many people have different ways to get the sum from a range of cells - without being too opinionated, which one of these will return the most exact result?

有没有道理呢?我知道很多人有不同的方法可以从一系列细胞中获得总和 - 而不是过于自以为是,其中一个会返回最准确的结果?

Sub testsums()

Dim metric1 As Integer, metric2 As Integer, metric3 As Integer

metric1 = Application.Sum(Range(("A1"), ("Z1")))

metric2 = Application.WorksheetFunction.Sum(Range(("A1"), ("Z1")))

metric3 = WorksheetFunction.Sum(Range(("A1"), ("Z1")))

End Sub

I'm working to reproduce my error - basically when looping through many rows (15,000+) and getting sums, some were returning zeroes where they shouldn't have been.

我正在努力重现我的错误 - 基本上当循环通过许多行(15,000+)并获得总和时,有些人返回的零点应该不存在。

1 个解决方案

#1


5  

  • Application.Sum(Range(("A1"), ("Z1")))

    That's a late-bound call against Excel.Application, resolved at run-time; as with any late-bound call (e.g. against Object or Variant), you get no IntelliSense, no auto-completion, and no compile-time validation, be it for typos in the name or for order or number of parameters. If the call is invalid or the function otherwise results in an error, this will return an Error value that you can validate with the IsError VBA function (of course if there's a typo in the function name what you'll get is a run-time error #438 "Object doesn't support this property or method").

    这是对Excel.Application的后期调用,在运行时解决;与任何后期绑定调用一样(例如针对Object或Variant),您没有获得IntelliSense,没有自动完成,也没有编译时验证,无论是名称中的拼写错误还是订单或参数数量。如果调用无效或函数否则会导致错误,这将返回一个Error值,您可以使用IsError VBA函数进行验证(当然,如果函数名中有拼写错误,您将得到的是运行时)错误#438“对象不支持此属性或方法”)。

    What makes this syntax work is the fact that the Excel.Application COM interface has a flag that makes it extensible - I'm not sure if it's extended with straight-up WorksheetFunction interface or if it's merely doubling-up the members, but anyway that's what's going on: you're calling members that don't exist on the Application interface at compile-time.

    使这种语法有效的原因是Excel.Application COM接口有一个标志,使其可扩展 - 我不确定它是否通过直接的WorksheetFunction接口扩展,或者它只是使成员加倍,但无论如何发生了什么:你在编译时调用Application接口上不存在的成员。

  • Application.WorksheetFunction.Sum(Range(("A1"), ("Z1")))

    That's an early-bound call against Excel.WorksheetFunction, resolved at compile-time; you get IntelliSense, auto-completion, and compile-time validation. A typo will fail to compile, as will missing required parameters. If the call is invalid or the function otherwise results in an error, this will raise a VBA run-time error that you can handle with an On Error statement using standard, VBA-idiomatic error handling.

    这是对Excel.WorksheetFunction的早期调用,在编译时解析;您将获得IntelliSense,自动完成和编译时验证。输入错误将无法编译,因为缺少必需的参数。如果调用无效或函数导致错误,则会引发VBA运行时错误,您可以使用标准的VBA惯用错误处理使用On Error语句处理该错误。

  • WorksheetFunction.Sum(Range(("A1"), ("Z1")))

    That's exactly the same as Application.WorksheetFunction.Sum, except it's not fully-qualified. If your project has a WorksheetFunction class, or if there's a WorksheetFunction object variable in scope, it will take precedence over a fully-qualified Application.WorksheetFunction call as far as resolution goes (which may result in compile errors). Otherwise, identical.

    这与Application.WorksheetFunction.Sum完全相同,只是它不是完全合格的。如果你的项目有一个WorksheetFunction类,或者如果在作用域中有一个WorksheetFunction对象变量,那么就分辨率而言,它将优先于完全限定的Application.WorksheetFunction调用(这可能导致编译错误)。否则,相同。


Which one is "more reliable" depends on exactly what you deem "reliable". Personally I consider compile-time resolution completely worth it, so the "most reliable" would be the fully-qualified early-bound version.

哪一个“更可靠”取决于您认为“可靠”的确切内容。我个人认为编译时解析完全值得,所以“最可靠”将是完全合格的早期版本。


推荐阅读
  • Opencv提供了几种分类器,例程里通过字符识别来进行说明的1、支持向量机(SVM):给定训练样本,支持向量机建立一个超平面作为决策平面,使得正例和反例之间的隔离边缘被最大化。函数原型:训练原型cv ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 如何用Matlab快速画出带有3D渲染效果的复杂曲面
    简要地介绍了一下如何用Matlab快速画出带有3D渲染效果的复杂曲面图,包括三维曲面绘制、光线、材质、着色等等控制,以及如何 ... [详细]
  • http:www.cnblogs.compirloarchive200909091563368.html以前操作Excel的话,一般都会去用Microsoft.Jet.OLEDB.4. ... [详细]
author-avatar
杨子忧愁_347
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有