Public Variable Not Always Updated in Class Object

Posted on 2014-03-13
Last Modified: 2014-03-15
Unfortunately, I need to use some Public Byte variables which serve as switch settings for certain functions in an OOP application.   There are also some Public Integer variables used to denote numbers of things.  

Question is: I have observed that within a class (instantiated object), that the Public variable could be changed (ByRef used in the Constructor) within a method of a class, but when I leave the class the Public variable is not updated to the values within the class, and takes on the old value before instantiating and going into the class.


1. Are Public variables updated in methods of classes?
2. What about constructors, it seems that what happens in New() is special as well(?)

The time has come for me to understand the rules regarding where Public variables are actually updated.
Question by:lep1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 29

Accepted Solution

Paul Jackson earned 500 total points
ID: 39928283
Public variables in an instantiated object will lose any changed value as the value is only changed in that instance of the object, unless it is saved back to a database or other storage medium outside the class.

If you want a Public variable to have the same value across the application you would need to use a static class that does not get instantiated, hence the same class is used by all calls to it as opposed to a new instance of the class being created when ever it is created using the new constructor.

More info about static classes here :
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39928318
Your question is a bit misguided. You ask, "Are Public variables updated in methods of classes?" But "public variables" where? In the same class? In a different class? In a module? You ask, "What about constructors, it seems that what happens in New() is special as well(?)" The only thing special about a constructor is that it creates a new instance of a class. That's it. We either need more detail or we need to see the code in question. What you have stated right now doesn't make the issue very clear.

Author Comment

ID: 39929133
"Public" refers to a public variable defined in a module.  I observed that such a variable can be set to a value prior to being used in the method of an instantiated object (class), and can take on different values within such a method, but when leaving the class this public variable is reset to the original value it had before being updated in the class method.  

Question is, why aren't the new values of the public variable (defined in a module) that are set inside the method not retained upon leaving the method?  Basically, under the current structure VB.NET will let you use but ignores updating of a project-wide public variable (defined as public in a module) that is changed in a class method.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39930008
What are the types of the variables in question?  Integer? Boolean? String? A class?

Author Comment

ID: 39930012
LVL 29

Expert Comment

by:Paul Jackson
ID: 39931015
Please post your code of the module and class.

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question