I'm not sure if this was asked before, but I couldn't find it. Suppose I have a procedure with a local variable inside it. Normally, that variable is destroyed after the function finishes running. But in some cases, I'd like for it to persist, like in this example:
Function myFunction()
Dim runCount As Integer
runCount = runCount +1
debug.print "This function is now running for the " & runCount & " time."
End Function
In this example, the code wouldn't work, because the runCount would be reset each time. Of course, the simplest solution would be to declare a global variable instead, but in some cases, I want to avoid that for the sake of simplicity, encapsulation or other reasons.
So, is there any way to have the local variable persist after the procedure has finished running?