Why can't I use β€œAny” as a name in VBA?

When trying to define an Any () function such as python, I found that I could not name anything "Any".

Attempting to name a function, Sub, Const, or any will cause a syntax error, and the VBA IDE will highlight it.

I know any not-so-wonderful name, but why does it throw a syntax error? The only reason I could think of is the reserved keyword , but it is not.

+5
source share
2 answers

VBA ( Visual Basic for Applications ) is not VB.NET, although they have the same "Visual Basic" and similar syntax. (Related documentation for VB.NET, not VBA.)

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

You may also encounter errors if you use a reserved word to indicate a control, object, or variable. Received error messages do not necessarily tell you that the reason is a problem with a reserved word.

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

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

To obtain updated information on this issue and comments, Microsoft declares on its page https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/as-any-is-not -supported-in-declare-statements :

Any data type was used with Declare statements in Visual Basic 6.0 and earlier to allow the use of arguments that can contain any data type. Visual Basic supports overloading, and so makes any data type obsolete.

0
source

Source: https://habr.com/ru/post/1200360/


All Articles