Declarations

As described earlier in this chapter in the discussion on data types, variables (including functions, which you can think of as a special type of variable) can be declared implicitly or explicitly. Although there's nothing fundamentally "wrong" with using implicit declaration, explicit declaration is generally a good idea because:

• Using the right data type is simply a matter of using the right tool for the job. The smaller a data type is (the less memory it uses), the faster it runs.

Note Although there might be situations in which you don't know the data type returned by a called procedure, which might make you inclined to rely upon implicit declaration, you should still explicitly declare the variable as Variant. Doing this doesn't create any performance gains, but you still get the other benefits of explicit declaration.

• Explicit declaration means if you mistype a variable name, Visual Basic recognizes the error and warns you of the mistake. Implicit declarations mean that any variable name not already known by Visual Basic results in a new variable.

• If you want to declare a variable with module-level or global scope, you have to explicitly declare the variable with the Dim, Private, or Public keywords.

• It's easier to find and understand the uses for variables that are explicitly declared, especially if they are consistently grouped at the beginning of a module or procedure.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment