April 2006
Beginner
1114 pages
98h 16m
English
You may have guessed that procedures have levels of scope, too. In fact, Visual Basic uses the same keywords (plus one) to define the scope of a procedure. The following procedure declarations show the scope and lifetime keywords in use (in bold):
PrivateSub Proc1( ) ' Private procedures are local to the module or class. End SubPublicSub Proc2( ) ' Public procedures are global to all open projects. End SubFriendSub Proc3( ) ' Friend procedures are public to the project that contains them. ' This is available only in classes. End Sub PrivateStaticSub Proc3( ) ' In Static procedures , all local variables are Static. ' Static procedures may be Private, Public, or Friend. End Sub
The default scope for procedures is public, so omitting the scope keyword is the same as declaring the procedure as Public. Most of the procedures you create will probably be public. Use Private or Friend when you want to restrict how others use a procedure. For example, declaring a function in a module as Private prevents users from using it as a user-defined function in an Excel formula.
Read now
Unlock full access