Home All Groups Group Topic Archive Search About
Author
12 Jun 2006 3:27 AM
BobRoyAce
I posted the post below in another newsgroup and it has been suggested
that this may be a better place to post it. See below:

---ORIGINAL POST BEGINS---
I have an application which is comprised of, among many other things, a
Main form which shows various user controls depending on which NavBar
link they click on. In addition, there are many Entity classes that I
created to support the application, one of which happens to be called
User. In my main form I currently instantiate a User object which
corresponds
to the user who logged in. The User object that is created
(g_oCurrentUser) is declared as Private in my Main form's code, but
there is a Public function (GetCurrentUser) that returns a pointer to
g_oCurrentUser.

My question is "Is there a way for the other entity classes to "get at"
the
g_oCurrentUser object from the main form? The reason I need to do this
is because I want to pull the current user's ID to use for populating
the fkLastUpdatedByUserID field of the entities when they have been
changed by the current user.

Is there a way to do this? I guess my question, more generally, is how
can I have Object variables that are accessible both to the Main form
and to other parts of the system (e.g. user controls that will be
created later and shown on the form, other Objects, modules, etc.)?

Author
12 Jun 2006 5:35 AM
Cor Ligthert [MVP]
Bob,

You can use a shared class or a module (which is a shared class with less
documentive value).

It this is not what you want or if you don't know how, than please reply.

Cor

Show quoteHide quote
"BobRoyAce" <b***@omegasoftwareinc.com> schreef in bericht
news:1150082851.379731.81830@i40g2000cwc.googlegroups.com...
>I posted the post below in another newsgroup and it has been suggested
> that this may be a better place to post it. See below:
>
> ---ORIGINAL POST BEGINS---
> I have an application which is comprised of, among many other things, a
> Main form which shows various user controls depending on which NavBar
> link they click on. In addition, there are many Entity classes that I
> created to support the application, one of which happens to be called
> User. In my main form I currently instantiate a User object which
> corresponds
> to the user who logged in. The User object that is created
> (g_oCurrentUser) is declared as Private in my Main form's code, but
> there is a Public function (GetCurrentUser) that returns a pointer to
> g_oCurrentUser.
>
> My question is "Is there a way for the other entity classes to "get at"
> the
> g_oCurrentUser object from the main form? The reason I need to do this
> is because I want to pull the current user's ID to use for populating
> the fkLastUpdatedByUserID field of the entities when they have been
> changed by the current user.
>
> Is there a way to do this? I guess my question, more generally, is how
> can I have Object variables that are accessible both to the Main form
> and to other parts of the system (e.g. user controls that will be
> created later and shown on the form, other Objects, modules, etc.)?
>
Author
12 Jun 2006 5:46 AM
BobRoyAce
I don't know if that's what I need, but sounds like I would want one of
them. I don't know how to do either, though, so would appreciate
guidance including steps and code samples if at all possible (brief, of
course). I am brand new to VB.NET and am using Visual Studio 2005.
Author
12 Jun 2006 8:21 AM
Cor Ligthert [MVP]
Bob,

You would not place values or objects that is for your complete project in
one UI (form)class as all classes could use it.

Therefore is the Shared Class (in fact it is placed on the mainstack of the
resulting endprogram, and therfore consumes constantly memory). In C
languages the name for this was Static, this word however does not so good
reflect the meaning, because the contents of everything is variable.
Therefore in VBNet it is Shared.

You can make this class as by instance below. (Just typed in so watch typos)

Public Shared Class TheClass 'MyClass is a special word
Private mTheField as String
Public Property TheField as String
Get
    Retunr mField
End Get
Set ............. I forever forget this text it is autotyped
    mField = value
End Set
End Class

This you can use in everywhere in your project by  instance the mainfrm

    me.Textbox1.text = TheClass.TheField

I hope this helps,

Cor



Show quoteHide quote
"BobRoyAce" <b***@omegasoftwareinc.com> schreef in bericht
news:1150091206.418178.141330@f6g2000cwb.googlegroups.com...
>I don't know if that's what I need, but sounds like I would want one of
> them. I don't know how to do either, though, so would appreciate
> guidance including steps and code samples if at all possible (brief, of
> course). I am brand new to VB.NET and am using Visual Studio 2005.
>
Author
12 Jun 2006 5:47 AM
BobRoyAce
I don't know if that's what I need, but sounds like I would want one of
them. I don't know how to do either, though, so would appreciate
guidance including steps and code samples if at all possible (brief, of
course). I am brand new to VB.NET and am using Visual Studio 2005.