Stattic Variable

L

Lee

<<sorry. Shld have posted my message here instead of the
General section>>

Hi! Friends.

Can someone help:

I wish to preserve the value of a variable (say n) each
time I run the procedure, I have:

Sub count()
Static n as integer

n=n+1

end sub

May I know how I can start with an initial value of n
other than 0. I use CALL sub, but doesnt work.

Many thanks.
..
 
J

J.E. McGimpsey

Check for possible solutions in the .misc group.


In general, it's better to stick to one thread, even if it's in the
wrong group so that answers don't get fragmented. The time to repost
is if you don't get any answers in the original group within a
reasonable time (an hour or twelve, perhaps).
 
T

Tim Williams

Always the same start number?

Tim

Sub dostatic()

Const X_START As Integer = 5
Static x As Integer

If x = 0 Then x = X_START

MsgBox x
x = x + 1
End Sub
 
M

Myrna Larson

Instead of using a static local variable, you could also use a module-level variable and a
separate sub that initializes it to whatever value you want.
 
M

Myrna Larson

Another option is that if you want the numbers to start with, say, 10, just add 10 to the
reported value.
 

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

Top