Hi,
I dont know what all access modifier's available in visual basic 6.0 and whats the default one (private or public).
Also for constants do we need to specify the access modifiers?
Thanks
Question 1: default is private. There are three: Public, Private and Friend.
Public is project wide for standard modules, enterprise wide for class modules. (A form is a class, therefore this applies to form modules too.) Constants may only be declared public or private in a standard module. Otherwise they are private and an access modifier isn't allowed.
Friend may be used only with methods, and not in Standard modules. If you're using an activeX exe or dll, then public becomes a member of the exposed interface, i. e. visible to clients of your component. Friend is only visible project wide.
Private is only visible in the module in which it's declared. Private and Dim are interchangeable at the module level (except constants in a standard module can't use dim). In a method, local variables have to use dim. (Or static, but that's a matter of lifetime rather than scope.)
for variables, dim is the same as private at the module level (declared in General Declarations). Rules for Public are the same as thoseDim is the only choice (not counting static, but that's not a question of access scope, rather one of lifetime) inside a procedure. Variables declared in a proc are visible only in that proc.
Constants may be declared public or private only in standard modules. Otherwise, they are private and you can't use an access modifier. (You can create a public or private enum, however, with constants in it.)
Hope this helps, and feel free to question further if I've left anything out.
Thanks Bod you covered what i was looking for .
I have never worked with vb 6.0 before and had been using vb.net for a year now so ......
You deserver a star
Which most advice suggests is actually just an older name for Public. It isn't. There are subtle differences which we've discussed in here before; a keyword search in this forum should find them. However I'd not bother searching, and not bother with Global.
Yeah, Global is considered obsolete. Once the concept of scope expanded beyond project-wide, access modifiers had to change. Global's scope is project wide, as is Public in a standard module, as is Friend in any other kind of module. Public in a class module is beyond project wide scope, for clients of the project can see anything declared public.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.