473,851 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Global" objects

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 fkLastUpdatedBy UserID 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.)?

Jun 12 '06 #1
4 1276
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

"BobRoyAce" <br**@omegasoft wareinc.com> schreef in bericht
news:11******** *************@i 40g2000cwc.goog legroups.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 fkLastUpdatedBy UserID 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.)?

Jun 12 '06 #2
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.

Jun 12 '06 #3
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.

Jun 12 '06 #4
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.tex t = TheClass.TheFie ld

I hope this helps,

Cor

"BobRoyAce" <br**@omegasoft wareinc.com> schreef in bericht
news:11******** **************@ f6g2000cwb.goog legroups.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.

Jun 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4256
by: Eddy Ilg | last post by:
Hi, I am having a problem with an application I am writing: I have 2 scripts called 'conf' and 'build'. Both define a variable named 'root' and import a module named 'helper'. In the helper module I want to access the root variable, that is _either_ in conf _or_ build. How can I do this?
7
2692
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global" seems to be recognised by Access in at least three cases:- 1) "Global Const". Recently someone in this group helped me resolve a problem, and it involved the use of a Global Const. By Googling "Global Const", I got plenty of hits -- but they...
5
3500
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
9
2499
by: Javaman59 | last post by:
I saw in a recent post the :: operator used to reach the global namespace, as in global::MyNamespace I hadn't seen this before, so looked it up in MSDN, which explained it nicely. My question is, do "global" and "::" always go together? Is there any other use for these operators, than as a pair? TIA,
4
3540
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public myVar as string, etc. It seems to me that the scope and duration are the same, as they both are there while the application is running, and both go away when it quits. I presume that one difference is that the application state can be "flushed," such...
2
3721
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How do I ensure that changes made to the "Global.asax.vb" file are immediately reflected in the "Global.asax" file? After I change to the "Global.asax.vb" file, the "Global.asax" file date modified does not change and I do not see the updated values...
8
8044
by: Hans Greif | last post by:
Hallo, hello, i try to implement a global dataset - singleton based. On www.bakterienforum.de i found a singleton implementation: sealed class SingletonCounter { public int Counter = 0;
5
4943
by: dave | last post by:
If I have a class that hold, for instance, user settings that should be accessible to the entire program logic, what is a good paradigm to use? In C++, I would have made it a global object, protected if necessary for thread safety. In C#, of course, there are no global objects. The Program object is static, so cannot contain object instances. While I could store it in my main form pass it around, that seems cumbersome. I could do a...
6
4247
by: Anders J | last post by:
Hi We have some code that runs in a EventReceiver ItemAdded handler. The code must be thread-safe since it is iterating a List to find the max number of a column and assigns it + 1 to the Item that was added. If it was not thread-safe, two items could get the same number (which must be unique). So how do we garantee this in the event handler? Is locking on "this" enough? I guess not since other types of Event Handlers could as well...
0
9897
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10728
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5933
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.