Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb6

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?

like image 654
Ben McCormack Avatar asked Mar 02 '10 19:03

Ben McCormack


People also ask

What does an exclamation mark before a variable mean?

If you have ever noticed a double exclamation mark (!!) in someone's JavaScript code you may be curious what it's for and what it does. It's really simple: it's short way to cast a variable to be a boolean (true or false) value.

What does '!' Mean in C programming?

It's a negation or "not" operator. In practice ! number means "true if number == 0, false otherwise." Google "unary operators" to learn more.

What does exclamation mark after variable mean?

The exclamation mark (non-null assertion) operator removes null and undefined from the type of an expression. It is used when we we know that a variable that TypeScript thinks could be null or undefined actually isn't. index.ts. Copied!

What does an exclamation mark before a variable mean in JavaScript?

In Javascript, the exclamation mark (“!”) symbol, called a “bang,” is the logical “not” operator. Placed in front of a boolean value it will reverse the value, returning the opposite.


2 Answers

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. Like the Fields property of an ADO Recordset object.

Somewhat inevitable with sugar is that it produces tooth decay. This is the reason you have to use the Set keyword in VB6 and VBA. Because without it the compiler doesn't know whether you meant to copy the object reference or the object's default property value. Eliminated in vb.net.

like image 148
Hans Passant Avatar answered Oct 02 '22 07:10

Hans Passant


The exclamation point is acting as a member access operator it seems...

Member Access Operators

To access a member of a type, you use the dot (.) or exclamation point (!) operator


I take that back. It is this:

Exclamation Point (!) Operator Use the ! operator only on a class or interface as a dictionary access operator. The class or interface must have a default property that accepts a single String argument. The identifier immediately following the ! operator becomes the string argument to the default property.

like image 30
Urda Avatar answered Oct 02 '22 05:10

Urda