June 11th, 2007, 4:46 pm
A variable name is an alias for the area of memory that VBA and Excel have decided to put the data.A global variable is in a fixed, known, unique place, and by making it global, you tell VA that you want it's name to be visible everywhere.But a parameter is a stack variable. It does not have a specific location.Consider the following function:function Factorial (x as double) as doubleDim StupidVariableThatJustHangsAround as doubleif x =0 or x =1 then factorial = 1elseFactorial = x * Factorial (x-1)END IFend functionThis function will call itself, multiplying x as it goes, and you will have many x's each with a different variable.Also you will have many instances of StupidVariableThatJustHangsAround, the local variable.You can make StupidVariableThatJustHangsAround static, and so only have one copy, but you can't have a static parameter.There is a way of doing this, but it is so quite overwhelmingly ugly that I don't recommend it.
Last edited by
DominicConnor on June 10th, 2007, 10:00 pm, edited 1 time in total.