How to declare a static/shared member in a class module?

J

Jezebel

For a variable shared by all the code within the class module, declare it at
the top of the module, outside an procedure code.

Static variable as declared as such within a procedure. The variable is not
available outside the procedure ,but retains its value for the life of the
object.
 
A

Alexandre

Thanks for reply

But i meant how do I declare a member(variable, method, event) that can be initialized whitout having to create an instance of the class. and that is common trough all instances of that class

This is refered to static in c#/java and shared in vb.ne

Thanks!
 
J

Jezebel

In VB/VBA these are called public variables: declared as such in any
ordinary module:

Public MyVar as Whatever

Usually considered bad programming practice, though. You don't normally need
them.


Alexandre said:
Thanks for reply.

But i meant how do I declare a member(variable, method, event) that can be
initialized whitout having to create an instance of the class. and that is
common trough all instances of that class.
 
A

Alexandre

From MSDN about vb.ne

SHARED
The Shared keyword indicates that one or more declared programming elements are shared. Shared elements are not associated with a specific instance of a class or structure. You can access them by qualifying them either with the class or structure name, or with the variable name of a specific instance of the class or structure

PUBLIC
The Public keyword confers public access on one or more declared programming elements. There are no restrictions on the accessibility of public elements

How do I declare a shared member in vba

Thanks!
 
J

Jezebel

VBA is not VB.Net


Alexandre said:
From MSDN about vb.net

SHARED:
The Shared keyword indicates that one or more declared programming
elements are shared. Shared elements are not associated with a specific
instance of a class or structure. You can access them by qualifying them
either with the class or structure name, or with the variable name of a
specific instance of the class or structure.
PUBLIC:
The Public keyword confers public access on one or more declared
programming elements. There are no restrictions on the accessibility of
public elements.
 
A

Alexandre

----- Jezebel wrote: ----

VBA is not VB.Ne



That is why him here asking questions. I would just like to know if its possible or not. If it is then how to do it

Can somebody who isn't clueless about what I'm talking about help

Thanks!
 
J

Jezebel

You've already had the answer. I'm sorry you don't like it.



Alexandre said:
----- Jezebel wrote: -----

VBA is not VB.Net



That is why him here asking questions. I would just like to know if its
possible or not. If it is then how to do it?
 
J

Jonathan West

Jezebel has given you the correct answer for VBA. There is no equivalent of
Shared in a class module in VBA.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Alexandre said:
----- Jezebel wrote: -----

VBA is not VB.Net



That is why him here asking questions. I would just like to know if its
possible or not. If it is then how to do it?
 
J

JB

Might help if in future you don't suggest the volunteers here are
"clueless"!
If you ask your question in the correct way the first time (make it clear
from the offset) you'll get a
quick answer (you might not like it but hey thats life dude!).
J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top