473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

some kind of Application Variable with Application Events???

Hi,

For a VB.NET 2005 application I need some kind Application Variable that
holds a value that can be accessed everywhere in the application. It should
also be available for a usercontrol in a seperate dll. Even more: I should
be able to trigger everywhere in the application when this variable changes.

I need it for some kind of Copy Paste operation of Documents in the
application. Not only the ID of what I want to copy must be available
everywhere (I could actually do this via the clipboard), but I should be
able to disable everywhere the "paste"-buttons (which are on every form)
when there isn't any copied, and they must be enabled when the user copied
something. So I kind of need a way to handle on different locations the
event.

Any idea how I should do this? I searched for some kind of
application-events, but didn't find a solution.

Any help our hints would be really appreciated!
Thanks a lot in advance!
Pieter


Nov 23 '05 #1
4 1083
Dear Pieter,
You can make a Singleton Class which extend Hashtable,
so it will accessable to you through out the application.
Q . I should be able to trigger everywhere in the application when this variable changes?

You can override the Add method of the Hashtable and do what you want
in that.

I hope it helps.
Regards,
Naveed Ahmad Bajwa
http://bajoo.blogspot.com/

Nov 23 '05 #2
Thanks, but I dson't think it will help me any further:

Let's say that I create such a class, and I make an instance of it when the
application loads: MyClass.
How will I handle in every form/class the MyClass.Changed-event?
"Bajoo" <Na**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Dear Pieter,
You can make a Singleton Class which extend Hashtable,
so it will accessable to you through out the application.
Q . I should be able to trigger everywhere in the application when this
variable changes?

You can override the Add method of the Hashtable and do what you want
in that.

I hope it helps.
Regards,
Naveed Ahmad Bajwa
http://bajoo.blogspot.com/

Nov 23 '05 #3
Pieter wrote:
For a VB.NET 2005 application I need some kind Application Variable that
holds a value that can be accessed everywhere in the application. It should
also be available for a usercontrol in a seperate dll. Even more: I should
be able to trigger everywhere in the application when this variable changes.

<snip>

As Bajoo suggested, singleton is your friend.

You declare a class to provide the functionality you need, say DocList,
with appropriate events for when the list changes:

Public Class DocList
Public Event Change(ByVal Sender As Object, ByVal E As EventArgs)
' ...
' ...
' ...

Then, in the class body, you declare both a shared variable to
represent your singleton, as well as a shared method to give access to
it:

' In the DocList class body
Private Shared mGlobalDocList As New DocList

Shared ReadOnly Property GlobalDocList As DocList
Return mGlobalDocList
End Property

In every form you declare a withevents reference to a DocList class:

Private WithEvents GlobalDocList As DocList

Then upon form intialization, you set the reference to the actual
GlobalDocList:

Sub Form_Load(...) Handles MyBase.Load
'...
GlobalDocList = DocList.GlobalDocList
End Sub

Of course, every form must handle the events generated by the doclist:

Sub GlobalDocList_Change(...) Handles GlobalDocList.Change
'...
End Sub

And that's all there is to it.

Now, for the custom control in the DLL, I suggest you add a custom
property, say,

Public Property DocumentsAvailable As Boolean
'...
End Property

which you can set from inside the form that holds the control. This way
you keep your control independent from (and unaware of) the DocList.

HTH.

Regards,

Branco.

Disclaimer: the snippets above are pure Air Code (TM), and give no
warranties. ;-)

Nov 23 '05 #4
Thanks! It seems that this is exactly what I want! I'll try it as fast as
possible!

Thanks a lot for the help!

Pieter

"Branco Medeiros" <br*************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Pieter wrote:
For a VB.NET 2005 application I need some kind Application Variable that
holds a value that can be accessed everywhere in the application. It
should
also be available for a usercontrol in a seperate dll. Even more: I
should
be able to trigger everywhere in the application when this variable
changes.

<snip>

As Bajoo suggested, singleton is your friend.

You declare a class to provide the functionality you need, say DocList,
with appropriate events for when the list changes:

Public Class DocList
Public Event Change(ByVal Sender As Object, ByVal E As EventArgs)
' ...
' ...
' ...

Then, in the class body, you declare both a shared variable to
represent your singleton, as well as a shared method to give access to
it:

' In the DocList class body
Private Shared mGlobalDocList As New DocList

Shared ReadOnly Property GlobalDocList As DocList
Return mGlobalDocList
End Property

In every form you declare a withevents reference to a DocList class:

Private WithEvents GlobalDocList As DocList

Then upon form intialization, you set the reference to the actual
GlobalDocList:

Sub Form_Load(...) Handles MyBase.Load
'...
GlobalDocList = DocList.GlobalDocList
End Sub

Of course, every form must handle the events generated by the doclist:

Sub GlobalDocList_Change(...) Handles GlobalDocList.Change
'...
End Sub

And that's all there is to it.

Now, for the custom control in the DLL, I suggest you add a custom
property, say,

Public Property DocumentsAvailable As Boolean
'...
End Property

which you can set from inside the form that holds the control. This way
you keep your control independent from (and unaware of) the DocList.

HTH.

Regards,

Branco.

Disclaimer: the snippets above are pure Air Code (TM), and give no
warranties. ;-)

Nov 23 '05 #5

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

Similar topics

12
by: Bill | last post by:
For my personal use I am accessing a railway timetable page, parsing its contents and then sending brief relevant information as the subject line of an email to be read on a mobile phone. The...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
4
by: Pieter | last post by:
Hi, For a VB.NET 2005 application I need some kind Application Variable that holds a value that can be accessed everywhere in the application. It should also be available for a usercontrol in a...
35
by: Justin Weinberg | last post by:
My thoughts on this.... http://msdn.microsoft.com/vbasic/Future/default.aspx?pull=/library/en-us/dnvs05/html/vb9overview.asp My thoughts: 1. Regarding Implicit types, I don't use type...
4
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
3
by: ApexData | last post by:
Hello I completed an application that worked great until I went to STARTUP and shut off all of the checkboxes. My code uses "Application.CurrentObjectName" to get the current Form name. All my...
3
by: rdemyan via AccessMonster.com | last post by:
Sometimes users (including myself) accidentally click on the application close icon in the application menu bar when they meant to just click on the 'X' for the form. Of course the app closes and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.