为什么我不能使用“任何"广告?作为VBA中的名称? [英] Why can't I use the "Any" as a name in VBA?

查看:86
本文介绍了为什么我不能使用“任何"广告?作为VBA中的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试定义类似python的 Any()函数时,我发现我无法命名任何"Any".

While trying to define an Any() function like python's, I found that I couldn't name anything "Any".

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

Attempting to name a Function, Sub, Const, or variable any will throw a syntax error and the VBA IDE will highlight it.

我知道任何并不是一个特别好的名字,但是为什么它会引发语法错误?我能想到的唯一原因是它可能是保留关键字,但不是.

I know any not a particularly great name, but why is it throwing a syntax error? The only reason I could think of was that it might be a reserved keyword, but it's not.

推荐答案

VBA( Visual Basic for Applications )是 not VB.NET,即使它们共享相同的"Visual Basic"绰号和相似的语法. (链接的文档适用于VB.NET,而不适用于VBA.)

VBA (Visual Basic for Applications) is not VB.NET, even though they share the same "Visual Basic" monikor and a similar syntax. (The linked documentation is for VB.NET, not VBA.)

VB6和VBA ()处理

VB6 and VBA in Microsoft Office (eg. Access, Excel) handles Any as a reserved word, and it cannot be used as an identifier:

如果使用保留字来命名控件,对象或变量,也可能会遇到错误.您收到的错误消息不一定告诉您保留字是造成此问题的原因.

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用作变量名或其他标识符没有问题:

In VB.NET, however, there is no problem using Any as a variable name or other identifier:

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

这篇关于为什么我不能使用“任何"广告?作为VBA中的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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