Tuesday, 15 May 2012

Why should I use the DIM statement in VBA or Excel? -



Why should I use the DIM statement in VBA or Excel? -

so there question on what dim is, can't find why want utilize it.

as far can tell, see no difference between these 3 sets of code:

'example 1 myval = 2 'example 2 dim myval integer myval = 2 'example 3 dim myval = 2

if omit dim code still runs, , after 2 or 3 nested loops see no difference in output when omitted. having come python, maintain code clean*.

so why should need declare variables dim? apart stylistic concerns, there technical reason utilize dim?

* i'm lazy , out of habit of declaring variables.

any variable used without declaration of type variant. while variants can useful in circumstances, should avoided when not required, because they:

are slower use more memory are more error prone, either through miss spelling or through assigning value of wrong info type

excel vba excel-vba

No comments:

Post a Comment