G Gerard wrote:
Hello
If Variant type is the data type that contains any kind of data type is
there a reason why one would not always use Variant when declaring
variables?
I'm sure someone can deliver a more convincing and accurate argument
than I, but here goes from this novice's point of view...
Typing variables correctly is a core skill for a programmer. To
understand why it is necessary to understand exactly what variables are
and how the system uses them.
Without going into the bits and bytes of every VBA variable type, or how
the system has to dynamically adjust to the data you feed it, I will say
you may very well get away with loosely typing variables in your code.
VBA and pre- dot.Net versions of VB are rather forgiving in this regard.
You may have all the memory and processing power you need to overcome
the overhead incurred by declaring everything as a Variant. With today's
typical hardware, maybe everyone else does too.
However taking this approach demonstrates a lack of understanding of the
data you are processing. What you gain in a blanket approach to variable
typing you lose in ability to control the data and handle exceptions. As
a programmer, if you understand the code you write and the data you are
processing, then you should have little difficulty assigning the most
efficient type to your variables.
That's my soapbox... I'll step down now.
--
Smartin