"Static" Behavior without Static Defn

S

Steve Drenker

The variable "sEscRate" is behaving as if it is declared Static in the
following subroutine & function. I'm puzzled why this is. Each invocation of
the function in the sub should be passing it the variable sEscRate with a
value of 0.05. I am expecting each time TestFunc will return 1.05, not the
totalized amount.

Why is it behaving as if it were declared Static? What am I missing here?

Sub TestSub()
Dim sEscRate As Single
Dim i As Integer

sEscRate = 0.05
For i = 1 To 10
Debug.Print TestFunc(sEscRate)
Next i
End Sub


Function TestFunc(EscRate As Single) As Single
EscRate = EscRate + 1
TestFunc = EscRate
End Function



Results Results
Obtained Expected
1.05 0.05
2.05 0.05
3.05 0.05
4.05 0.05
5.05 0.05
6.05 0.05
7.05 0.05
8.05 0.05
9.05 0.05
10.05 0.05
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top