a static type in vb.net

almubarmeg

New member
Joined
Aug 7, 2004
Messages
2
Programming Experience
3-5
Hello all,

Can any body tell me why the value 'counter' is not changing every time i click the button:

sub button1_click()

Static counter as integer
counter = counter+1

response.write(counter)
End sub

what i want is adding the previous value of counter to the new one each time i click the button.

Any help: please
 
Solution.

Static is a Function level keyword.....it means

The Static keyword indicates that one or more declared variables are static. Static variables remain in existence and retain their latest values after termination of the procedure in which they are declared.

What u said u what to do is ..
what i want is adding the previous value of counter to the new one each time i click the button.

Solution:

Static counter as integer OR Dim counter as integer

sub button1_click()

counter = counter+1
response.write(counter)
End sub
 
Hello

i didn't see any solution in your answer.
I have tried usingthe shared type and it works

eg:) Shared counter as integer.


Thank you anyway
 
here's also what you can do:

" Windows Generated Code " <at the top of the form's code>
private mintCounter as Integer = 0


sub button1_Click
mintCounter += 1

...other code...

end sub
 
Back
Top