Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bang Notation and Dot Notation in VBA and MS-Access

While perusing an application that I'm documenting, I've run across some examples of bang notation in accessing object properties/methods, etc. and in other places they use dot notation for what seems like the same purpose.

Is there a difference or preference to using one or the other? Some simple googling only reveals limited information on the subject with some people actually using it in opposite cases. Perhaps there is a coding standards section from MS somewhere that indicates the method of madness?

like image 623
Nitrodist Avatar asked May 27 '10 18:05

Nitrodist


People also ask

What is bang notation?

The bang (!) notation specifically denotes that what follows is a member of a collection. In the case of a reference such as Forms! FormName! ControlName, "FormName" is a member of the Forms collection, and ControlName is a member of that form's default collection, the Controls collection.

What is the purpose of dot notation in Excel VBA programming?

Excel VBA uses dot notation to separate the various things you can access and manipulate with the programming language. Dot notation is hierarchical, and usually starts with an object. (In Excel, an object is the thing you're trying to manipulate, such as a worksheet.) After the object, you type a dot.


1 Answers

Despite the (formerly) accepted answer to this question, the bang is not in fact a member or collection access operator. It does one simple and specific thing: The bang operator provides late-bound access to the default member of an object, by passing the literal name following the bang operator as a string argument to that default member.

That's it. The object doesn't have to be a collection. It doesn't have to have a method or property called Item. All it needs is a Property Get or Function which can accept a string as the first argument.

For much more detail and proof, see my blog post discussing this: The Bang! (Exclamation Operator) in VBA

like image 191
Joshua Honig Avatar answered Oct 03 '22 02:10

Joshua Honig