I believe I read somewhere that in VBA, if you Dim
a variable in a function or a module, it doesn't matter whether it's at the top or anywhere else in the module or function. I read that the compiler will scan for the Dim
statements when it enters a Function or Module and allocates the memory, and then jump back to the top and start executing code.
I also believe it is personal preference for programmers in VBA to either Dim
at the top or Dim
as they go, I prefer the second option. My question is whether there is any official documentation on exactly how the compiler handles the Dim statements or if it can be demonstrated that the above assertion is true.
I would love to read in detail on how the compiler handles the Dim statements as to when it allocates memory, i.e., before executing the code or as it comes across the dim statements. Can that be demonstrated?