njsokalski
Well-known member
- Joined
- Mar 16, 2011
- Messages
- 102
- Programming Experience
- 5-10
I should probably be kicked out of the development field for not knowing this, but I'll ask it anyway. I have a Form with multiple Buttons, all of which modify the same variable. However, each time the variable gets reset. Here is what my code looks like:
However, every time I click one of the buttons, myvar gets reinitialized before the Click eventhandler's code is executed, almost as if the first line of both eventhandlers was:
myvar=New MyClass()
I want myvar to maintain it's value between events. How can I do this, or in what Class do I need to define it so that it only gets initialized once? I'm sure this is a very simple question for people that have their experience in Windows Forms, but even though I have been doing VB.NET for almost 10 years, most of my experience is in ASP.NET and Silverlight, so I just need to get caught up in Windows Forms. Thanks.
Public Class frmTest Private myvar As New MyClass() Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click 'Code to modify myvar End Sub Private Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click 'Code to modify myvar End Sub End Class
However, every time I click one of the buttons, myvar gets reinitialized before the Click eventhandler's code is executed, almost as if the first line of both eventhandlers was:
myvar=New MyClass()
I want myvar to maintain it's value between events. How can I do this, or in what Class do I need to define it so that it only gets initialized once? I'm sure this is a very simple question for people that have their experience in Windows Forms, but even though I have been doing VB.NET for almost 10 years, most of my experience is in ASP.NET and Silverlight, so I just need to get caught up in Windows Forms. Thanks.
Last edited by a moderator: