Simple variable access question, please answer..

  • Thread starter Thread starter Unknown
  • Start date Start date
U

Unknown

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..
 
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++;
}
 
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.
 
(e-mail address removed) ("Jeffrey Tan[MSFT]") wrote in
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 :).
 
Back
Top