If n < 1291 ThenĪll local elements, even if they are Static variables, are private to the procedure in which they appear. You cannot declare any element using the Public keyword within a procedure. Module Scopeįor convenience, the single term module level applies equally to modules, classes, and structures. You can declare elements at this level by placing the declaration statement outside of any procedure or block but within the module, class, or structure. When you make a declaration at the module level, the access level you choose determines the scope. The namespace that contains the module, class, or structure also affects the scope.Įlements for which you declare Private access level are available to every procedure in that module, but not to any code in a different module. The Dim statement at module level defaults to Private if you do not use any access level keywords. However, you can make the scope and access level more obvious by using the Private keyword in the Dim statement. In the following example, all procedures defined in the module can refer to the string variable strMsg. When the second procedure is called, it displays the contents of the string variable strMsg in a dialog box. ' Put the following declaration at module level (not in any procedure). StrMsg = "This variable cannot be used outside this module." ' Put the following Sub procedure in the same module. If you declare an element at module level using the Friend or Public keyword, it becomes available to all procedures throughout the namespace in which the element is declared. With the following alteration to the preceding example, the string variable strMsg can be referred to by code anywhere in the namespace of its declaration. ' Include this declaration at module level (not inside any procedure). Namespace scope includes nested namespaces. An element available from within a namespace is also available from within any namespace nested inside that namespace. If your project does not contain any Namespace Statements, everything in the project is in the same namespace. In this case, namespace scope can be thought of as project scope. Public elements in a module, class, or structure are also available to any project that references their project. Local variables are a good choice for any kind of temporary calculation, for the following reasons: When you declare a variable, you should keep in mind the following points when choosing its scope. Local variable names are not susceptible to conflict. For example, you can create several different procedures containing a variable called intTemp. As long as each intTemp is declared as a local variable, each procedure recognizes only its own version of intTemp. Any one procedure can alter the value in its local intTemp without affecting intTemp variables in other procedures. Local variables consume memory only while their procedure is running. Their memory is released when the procedure returns to the calling code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |