Correct syntax to make Class Function Private yet callable by instances of Class (1 Viewer)

mdlueck

Sr. Application Developer
Local time
Yesterday, 23:02
Joined
Jun 23, 2011
Messages
2,631
Greetings,

I would like to make a function within a class Private, yet retain ability to call the function via "Me.FuncName" within the class.

At first I thought to change Public to Private for this particular Function in the Class. Other Functions in the class could not call it via "Me.FuncName"

I dropped the Private declariaton and now other functions in the class may call "Me.FuncName", however elsewhere in the program that use instances of this class, I see the Private FuncName showing up, via the VBA AutoComplete assistance.

1) So, is there no need to declare Class Funcs as Public since they show up without?

2) And how to make a Func Private, callable by the class itself only?
 

vbaInet

AWF VIP
Local time
Today, 04:02
Joined
Jan 22, 2010
Messages
26,374
1) So, is there no need to declare Class Funcs as Public since they show up without?
Yes it makes no difference but it's always good to be explicit. Functions are Public as default whereas (I believe) variables are Private as default.


2) And how to make a Func Private, callable by the class itself only?
Not possible I'm afraid. VBA doesn't support any other scope declaration keywords. VBA doesn't fully support OOP as well.
 

mdlueck

Sr. Application Developer
Local time
Yesterday, 23:02
Joined
Jun 23, 2011
Messages
2,631
Not possible I'm afraid. VBA doesn't support any other scope declaration keywords.

eeewww... That is unfortunate that Private is not supported. I guess I will really discourage direct calling in the comments. (shrug).
 

mdlueck

Sr. Application Developer
Local time
Yesterday, 23:02
Joined
Jun 23, 2011
Messages
2,631
In fact I went as far as placing the prefix "Priv_" in the front of the name of the function. :D That way it is a bit more obvious in the VBA editor which smart guesses what you might be typing.
 

vbaInet

AWF VIP
Local time
Today, 04:02
Joined
Jan 22, 2010
Messages
26,374
All you do is simply declare it as Private and don't use the Me. syntax when you call it within the class. Just call it using the function name.
 

Users who are viewing this thread

Top Bottom