8Understanding VBA
Finally, whereas VBA uses a single equals sign (=) for both comparison and assignment,
Java and JavaScript use a single equals sign (
=) for assignment and two equals signs (==)
for Boolean comparison. (For more information on Boolean comparison and assignment
in VBA, see “Using Boolean comparison and assignment” on page 15.)
VBA compared with C and C++
Visual Basic — similarly to C and C++ — uses functions. In VB, functions can be used
to return a value but subroutines cannot. In C and C++, however, functions are used
regardless of whether you want to return a value. (For more information on functions
and subroutines, see “Building functions and subroutines” on page 12.)
VBA allocates and frees memory “transparently.” In C and C++, however, the
developer is responsible for most memory management. This makes using strings in
VBA even simpler than using the
CString class in C++.
Finally, whereas VBA uses a single equals sign (
=) for both comparison and assignment,
C and C++ use a single equals sign (
=) for assignment and two equals signs (==) for
Boolean comparison. (For more information on Boolean comparison and assignment in
VBA, see “Using Boolean comparison and assignment” on page 15.)
VBA compared with Windows Script Host
Windows Script Host (WSH) is a useful addition to Windows for doing occasional
scripting and automation of Windows tasks. WSH is an out-of-process automation
controller that can be used to control WordPerfect Office X5. However, because WSH
scripts cannot be compiled (and must be interpreted as they are executed) and must be
run out of process, they tend to be slow.
WSH is a host for a number of scripting languages, each of which has its own syntax.
However, the standard language used by WSH is a macro language resembling Visual
Basic, so for standard scripts, the syntax is the same as in VBA.
What are the main elements used in VBA?
If you’ve ever developed object-oriented code in C++, Borland® Delphi®, or Java,
you’re already familiar with the concepts of “classes,” “objects,” “properties,” and
“methods,” but let’s re-examine them in greater detail as they apply to VBA.
A class is a description of something. For example, the class “car” is a small vehicle with
an engine and four wheels.