RadhaKrishnaKiJaya
asked on
Public variable
Hi Experts,
How to create a public variable which can be used only in the form. Suppose I have form1.aspx. How can I define a public variable which can be used only in form1 .no other form should able to access it.
How to create a public variable which can be used only in the form. Suppose I have form1.aspx. How can I define a public variable which can be used only in form1 .no other form should able to access it.
ASKER
Thank you for your reply. When it is private is it shared by only one instance or multiple instance? I think it for one instance only, just want to conform.
A private variable is not shared at all. If you are wanting to *Share* a variable (in VB terms and .NET definitions), then you would mark it as Shared. Methods, Properties and Fields defined within Modules are inherently Shared.
That being said, if you instantiate a form (which is a Class object); e.g. -
-saige-
That being said, if you instantiate a form (which is a Class object); e.g. -
Dim frm As New Form1
Then the object that instantiated frm has access to frm. If frm, by definition of Form1, contains a public field/property called someRandomThing, then the object that instantiated frm has access to this field/property.-saige-
ASKER
Hi,
When I declare as "Private MyVariable As Integer" still I can not access it in all the sub of that class. But When I declared as
"Private Shared MyVariable As Integer" then I can access it from all the subs. Is that the right way?
Thanks.
When I declare as "Private MyVariable As Integer" still I can not access it in all the sub of that class. But When I declared as
"Private Shared MyVariable As Integer" then I can access it from all the subs. Is that the right way?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private MyVariable As Integer