Specifies that an element is related to the class, structure, or procedure in which it is declared, and not some variable.
When you make an element with
@Shared in a class or structure, the member is available to all instances.
Usually each instance keeps a different copy.
@Shared, you can make a variable that all instances of a class have access to, but other code cannot.
When you declare a local variable with
@Shared in a procedure, it keeps its value between procedure calls.
Usually a local variable releases its memory when execution in the scope completes.
@Shared, the next time your code calls the procedure, the variable is not re-initialized, and keeps the same value.
- Declaration context
@Sharedis permitted in
- Combined modifiers
- You cannot combine
@Sharedwith most other modifiers. But you can combine it with
- You get access to a shared member of a class or structure through its qualified name.
That is the name of the class or structure, a dot (
.), and the name of the member. You cannot get access to a shared member through a variable of the class or structure.
- Implicitly Shared
- Some declarations cannot accept
@Shared, but are shared implicitly. These include
Const, in all scopes, and all declarations in module scope.
- Dim Statement
- Function Statement
- Method Statement
- New Statement
- Object Statement
- Property Statement
- Sub Statement