Access to instance of a class from a different module

triplemaya

Member
Joined
Aug 27, 2006
Messages
15
Programming Experience
Beginner
I have an object - UpTime - which keeps track of elapsed time using a standard timer. This is instantiated in the main program flow. Under certain conditions the user is given an option to start again, in a dialog box, and then the timer needs to be zeroed. The problem is that when the ok button is pressed, the program is off in the OK Button Click code of the dialog box, and from there I can't access the instance of the UpTime object. My apologies for this very basic question, but could someone please show me how to do this.

I have declared a shared function reset() in the UpTime class, which the OK Button Click code can call, but this, of course, cannot access instance members without a reference to the instance. In another language I could declare a static variable, say, doReset, and then the instance can check this variable at every access of the internal data, but "static is not valid on a member variable declaration" - squiggly line - so that's out. Besides, that doesn't seem very satisfactory. Equally I can write to the registry and then check that from within UpTime with every access, but that is pretty horrible also.

Declaring the instance of UpTime Public and / or Shared doesn't make it visible in the other module, though at microsoft the visibility of Public variables is stated as
" Anywhere in or outside of a project".

My declaration of the instance is
#Region "Global Variables"
Dim upTime as new UpTime()
 
here is a sample of the fiirst 9 lines of one of my modules. All the variables I have declared public here are accessible through my entire project and beyo9nd into other projects in the solution if they use the right namespace qualifiers etc

VB.NET:
Module Universe

    Public WindowWithData As Color = Color.FromArgb(239, 239, 255)

    Public oracleDataAdapter As New System.Data.OracleClient.OracleDataAdapter()
    Public oracleConnection As New System.Data.OracleClient.OracleConnection(My.Settings.ConnectionString)

    Public PopulatedLookupDS As LookupDS = New LookupDS()

    Public ReadOnly appName As String = "ddhub"

    Private APPS_PREFSTableAdapter As New DDHub.LookupDSTableAdapters.APPS_PREFSTableAdapter

    Private cachedColors As New Hashtable()

try arranging your code in a similar way. If there is to be only one UpTime, why dont you make that a module instead of a class?
 
Back
Top