Static Integer

  • Thread starter Thread starter Wolf Saenger
  • Start date Start date
W

Wolf Saenger

smaple:

sub SomeSub()
static i as integer = 1
i+= 1
end Sub

strange as initial Value means first call the variable = has as default max
( 243..... ) integer as value.

is this normal?

Wolf
 
Since you only incriment the value, are you saying in the debugger that you
look at the value on the first call and it is not 1 or 2 when you stop at the
i+=1 line?
 
Since you only incriment the value, are you saying in the debugger
that you look at the value on the first call and it is not 1 or 2 when
you stop at the i+=1 line?
Thats ok

no the initial Value is i = Integer.Max
I was expecting i = 0
 
Wolf Saenger said:
Thats ok

no the initial Value is i = Integer.Max
I was expecting i = 0

The initial value should be 1 because you are initializing the static
variable to 1. However, after the first call the value of 'i' is 2.
 
Hello Herfried K. Wagner [MVP],
The initial value should be 1 because you are initializing the static
variable to 1. However, after the first call the value of 'i' is 2.
Sorry it must be 1 Correct!
but it is the max value of a integer
so I'm astonished!
 
Wolf Saenger said:
Sorry it must be 1 Correct!
but it is the max value of a integer
so I'm astonished!

* How do you call the method?
* How do you determine the value of 'i'?
 
Wolf Saenger said:
Sorry it must be 1 Correct!
but it is the max value of a integer
so I'm astonished!

I can't repro the problem in VB 2003, 2005, 2008. I single stepped into the
procedure. Before the assignment of 1, the value is 0. After the assignment,
it is 1. After the increment it is 2. Everything as expected.

When and where do you see the value?


Armin
 

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

Back
Top