Burrgogi
Well-known Member
- Joined
- Nov 3, 2005
- Messages
- 570
- Office Version
- 2010
- Platform
- Windows
Dim is short for Dimension and is the way in which you define the data type for each variable.
If you leave out the Dim keyword then the line will be invalid syntax so the code will not compile.
message = "hello world!"
debug.print message
I am interpreting Burrgogi's statement literally:Not necessarily. The DIM statement is never necessary in VBA. It is only a standard by programmers as an attempt to avoid confusion when projects become very large.
E.G. - If your "Require variable declaration" option is OFF or there is no OPTION EXPLICIT statement in a module, VBA acts just like PHP:that'll output just the same as a DIMMED "message" variable.Code:message = "hello world!" debug.print message
Burrgogi said:In the context of the thread that I pointed out, what would happen if the programmer typed cell as range (leaving the 'Dim' out of macro).
cell As Range
It is extremely poor practice to implicitly declare variables and it should not be encouraged. Option Explicit has many more benefits than the one you suggest and should be used regardless of the size of the project. I listed some advantages here.The DIM statement is never necessary in VBA. It is only a standard by programmers as an attempt to avoid confusion when projects become very large.