tags:

views:

311

answers:

2

What does putting an exclamation point (!) in front of an object reference variable do in Visual Basic 6.0?

For example, I see the following in code:

    !RelativePath.Value = mstrRelativePath

What does the ! mean?

+2  A: 
Urda
+7  A: 

It is almost certainly a statement inside a With block:

  With blah
    !RelativePath.Value = mstrRelativePath
  End With 

which is syntax sugar for

  blah("RelativePath").Value = mstrRelativePath

which is syntax sugar for

  blah.DefaultProperty("RelativePath").Value = mstrRelativePath

where "DefaultProperty" is a property with dispid zero that's indexed by a string.

Hans Passant
Is anything more than syntatic sugar?
Ben McCormack
@Ben: I cannot parse your question. Guessing: no, it is just sugar.
Hans Passant
Ben probably means that all higher level programming is "just syntactic sugar" - in theory you could write the same functionality in machine code.
MarkJ
@nobugz I forgot the word "it." Is *it* anything more than syntatic sugar? The reason I ask the question is because in your question you said, "which is syntax sugar for". Is it *only* syntax sugar? I'm wondering if perhaps it might help speed up runtime of the application as well or are there other side effects with using a `!` instead of writing out all of the code.
Ben McCormack
No, the exact same code gets generated.
Hans Passant