Posted to microsoft.public.excel.programming
|
|
Dim
Thank you all,
That helps alot!!
"Jim Rech" wrote:
The main reason to Dim variables, in conjunction with Option Explicit which
requires variables to be declared, is to prevent you from accidentally
creating 'new' variables via making typos. If you dim MyRange as Range and
later start using MyRg you'll get a compiler warning.
Other advantages include being able to set the scope of the variable
(global, module, procedural) and to use the most efficient data type -
undeclared variables are always variants which take more memory and are
'slower' than more specific variables like integers.
And don't forget Intellisense. When you declare a MyRange as Range and then
type "MyRange." VB pops up the methods and properties of Range objects which
makes your programming easier and less error prone.
--
Jim
"tjh" wrote in message
...
| What is the primary benfit of a Dim statement -- if the variable does not
| cause any name or data type confusion.
|
| I understand that it is to declare a variable. However, I seem to be able
to
| run macros without any problem no matter if I declare the varaiable or do
not.
|
| For instance, I use For Next loops similar to:
|
| Dim intI as integer
| For intI = 1 to 25
| ................
| ................
| Next intI
|
| but these loops work the same weither I declare the variable or not.
|
| Any thoughts?
|
| Thank You,
|
|
|
|
|