By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

Simple variable access question, please answer..

P: n/a
Hello i am new to C# and am having trouble with variable access.. What I am
doing is just making a timer, and within the tick event I want a variable
to increase a number.. for example

tick event:

integervar++;

end event

however each time I do this, visual studio is telling me that integervar
does not exist even though I have defined it in the initializecomponents
method..
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
From your description, it appears that "integervar" only has local scope
within InitializeComponents. You need to declare it at the class scope
instead, then it will be visible to both InitializeComponents and the tick
event handler:

class MyClass
{
private int integervar;

private void InitializeComponent()
{
integervar = 0;
}

private void timer1_Tick(object sender...
{
integervar++;
}

"Unknown" <Un*****@Unknown.COM> wrote in message
news:Xn*******************************@140.99.99.1 30...
Hello i am new to C# and am having trouble with variable access.. What I am doing is just making a timer, and within the tick event I want a variable
to increase a number.. for example

tick event:

integervar++;

end event

however each time I do this, visual studio is telling me that integervar
does not exist even though I have defined it in the initializecomponents
method..

Nov 15 '05 #2

P: n/a

Hi,

Do you still have any concern?
If you have anything unclear, please feel free to tell me, I will work with
you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3

P: n/a
v-*****@online.microsoft.com ("Jeffrey Tan[MSFT]") wrote in
news:2p*************@cpmsftngxa08.phx.gbl:

Hi,

Do you still have any concern?
If you have anything unclear, please feel free to tell me, I will work
with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.


Thank you for your help, I have no problems anymore :).

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.