gpt4 book ai didi

vba - 为什么我不能在 VBA 中使用 "Any"作为名称?

转载 作者:行者123 更新时间:2023-12-02 07:30:15 26 4
gpt4 key购买 nike

在尝试定义像 python 那样的 Any() 函数时,我发现我无法将任何内容命名为“Any”。

尝试命名函数、Sub、Const 或变量 any 将引发语法错误,VBA IDE 将突出显示该错误。

我知道any不是一个特别好的名字,但为什么它会抛出语法错误?我能想到的唯一原因是它可能是 reserved keyword ,但事实并非如此。

最佳答案

VBA ( Visual Basic for Applications ) 不是 VB.NET,尽管它们共享相同的“Visual Basic”名称和相似的语法。 (链接的文档适用于 VB.NET,而不是 VBA。)

Microsoft Office(例如 Access、Excel)中的 VB6 和 VBA 处理 Any as a reserved word ,并且不能用作标识符:

You might also encounter errors if you use a reserved word to name a control, an object, or a variable. The error messages you receive don't necessarily tell you that a reserved word is the cause of the problem.

但是,在 VB.NET 中,使用 Any 作为变量名或其他标识符没有问题:

Dim Any as String = "Hello world!"    'works just fine in VB.NET

关于vba - 为什么我不能在 VBA 中使用 "Any"作为名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25316973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com