bang versus dot

Guus2005

AWF VIP
Local time
Today, 13:56
Joined
Jun 26, 2007
Messages
2,642
I always use a dot and never an exclamation mark.
Is there a difference? Is one faster?
And line 1000 compared to 2000?

Example:
Code:
1000        frmProgress!cboProcesstatusG = rs!StatusProces
1001        frmProgress!txtDatVooraanVerzondenG = Format(gsJAL_G!DatVooraanVerzonden, "dd-mm-yyyy")
versus
Code:
2000        frmProgress.cboProcesstatusG = rs.Fields("StatusProces")
2001        frmProgress.txtDatVooraanVerzondenG = Format(gsJAL_G!DatVooraanVerzonden, "dd-mm-yyyy")

Thanks!
 
This has been answered many times but most of the explanations are incorrect, incomplete, or simply a consequence of the below. Bang does one thing only

It causes the runtime to invoke the default member of an object and pass the name following the bang as a string argument.

I have never seen anything that would suggest any difference in any real terms. Obviously Dot has more advantages with ability to use variable names and intellisense. Bang has only one advantage in that it is nice short hand. And in certain "expressions" such as queries, calculated controls, and conditional format you have to use this form. Bang does one thing. It causes the runtime to invoke the default member of an object and pass the name following the bang as a string argument. Thus
RS!FieldName is the same as RS.fields("FieldName") since fields is the default member of the recordset collection.

The dot is early-bound and the bang is late-bound, not sure what the impact is in practical terms but that can cause problems with debugging.
me!name will compile and then error at runtime 'Not Desired
me.SomeMispelledControlname will not compile 'Desired
me!someMispelledControlName will compile 'Not Desired

They are not equivalent beyond that. The dot is the one and only way to access a named public member (property, method) of an object not through a collection.

The one seemingly apparent exception is the fields on a form. The default member of a form is the controls collection and there is not even a fields collection. This was explained by Sonic8 in that the fields of the recordsource are added to the default controls collection as a pseudo control in a special way. They do not appear in the control count.
 
I always use a dot and never an exclamation mark.
Is there a difference? Is one faster?
And line 1000 compared to 2000?
Guus,
I think MS has seriously screwed this syntax up, because I've run into countless errors from version to version and object to object with those different version where sometimes bangs work and sometimes periods work. I believe i wrote a FAQ on this too, like years ago, but it addresses referencing subforms controls and the syntax that works and syntax that doesn't work. and even in there with all my testing, some of my examples use "." and some use "!".

I believe it's different when using them in the GUI properties vs. using them in code. I don't really believe there is any consistency to any of this, given the fact that, again, countless people have posted questions on this forum addressing this same issue. and their question usually revolves around the fact that their syntax errors out. I would doubt that MS's websites could clarify this to any degree. After all, Access is not profitable for them so they probably pass the development off to low-level programmers that don't pay much attention to detail.
 
My understanding is that dot is used when referencing "Access" methods and properties and bang is used when referencing user defined methods and properties
That is in no way correct and not another way to say what I said. I think you may mean this in reverse, but still that is would not be correct. The definition I provided is 100% correct. There is no way ! works on a method of either an access or user defined object. There is no property that this works on that is not the default property. There is no property that this works on that is also not a collection.
 
Have a look through this thread.

https://www.access-programmers.co.uk/forums/showthread.php?t=202806&highlight=bang+vs+dot

It addresses it better than I could because I'm sure I don't remember all the reasons why you choose one over the other at a given moment. In particular, Galaxiom has a post fairly early in that thread that goes over all the choices and meanings.

Unfortunately it was still in early days of my experience and although largely functionally correct it is not technically correct.

Have a look at what I posted in this thread.
 
Thanks, G. I missed the later thread in my search for Guus, but what the heck, he's getting a pretty good answer now! (or is that now.) ?
 
Thanks everyone, especially Pat!

I have always preferred the dot above the bang because a dot always showed intellisense. I wasn't aware that nowadays the bang also shows intellisense.

Secondly i was searching for a reason to always use Me in front of controlnames. Your explanation is very clear. I know that my code runs a tiny bit faster but every millisecond adds up.
It is just good practise to do it this way.

Code:
with me
    .cboSomething.enabled = True
    .chkActive.visible = True
end with

I am creating a document about good practises in Access programming to normalise the coding and to always use fast code. e.g. To (almost) always use the faster domain function alternatives (Tlookup) and use the string function like Trim$, Left$ and such. There was a microsoft document once but i can't find it anymore. (this is not a new question)

These remarks will definitely find a place there.

Thanks again!
 

Users who are viewing this thread

Back
Top Bottom