The first method??”called
implicit declaration??”is to let VBA automatically create the variables for you. As with most things
that are not carefully controlled, you??™ll find that letting VBA prepare your variables for you is not
necessarily a good idea and does not lead to the best performance or efficiency in your programs.
(See the ???Comparing implicit and explicit variables??? section, later in this chapter, for a comparison
of implicit declaration with the alternatives.)
Implicit declaration means that VBA automatically creates a variant data type variable for each
identifier it recognizes as a variable in an application. (Variants are discussed in the ???Working with
Data Types??? section, later in this chapter.) In the following listing, there are two implicitly declared
variables (strFirstName and strLastName).
Private Sub Combine_Implicit()
strFirstName = txtFirstName
strLastName = txtLastName
txtFullName = strFirstName & ??? ??? & strLastName
End Sub
TIP
391
Mastering VBA Data Types and Procedures 11
The second approach to declaring variables is to explicitly declare them with one of the following
keywords: Dim, Static, Private, or Public.
Pages:
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862