473,815 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

events with array variable?

Hi,
I have a class let's say class1 that raises an event, let's say OnEvent.
In another class, let's say class2, I have an array of Class1. I want to be
able to trap the events fired by class1 within class2 and know (if possible)
the index of the class1 that fired the event. Is there a way? because
withevents does not work.

Here is some code you could rely on if you don't understand what I just
explain :

Class Class1
public event OnEvent()
End Class

Class Class2
private m_MyArray(10) as Class1 'WithEvents doesn't work, so I don't
write it
End Class

So, what should I do from there to catch the events fired by class1 into
class2? I figured it could be with AddHandler, but I'd have to store the
index in Class1 and I don't want to do that if possible. If it's the only
way, I'll do it this way, but I want to know if there is a better way.

Thanks

ThunderMusic
Nov 21 '05 #1
4 1106

You can store the array of classes in a SortedList and use IndexOfKey
to determine the index of the class when the event is broadcasted.

Or you can use a third class that just stores the index and proxies
the event along with the index.

HTH,

Sam
On Mon, 24 Jan 2005 16:01:29 -0500, "ThunderMus ic"
<NO*******@symp atico.caSPAMATA LL> wrote:
Hi,
I have a class let's say class1 that raises an event, let's say OnEvent.
In another class, let's say class2, I have an array of Class1. I want to be
able to trap the events fired by class1 within class2 and know (if possible)
the index of the class1 that fired the event. Is there a way? because
withevents does not work.

Here is some code you could rely on if you don't understand what I just
explain :

Class Class1
public event OnEvent()
End Class

Class Class2
private m_MyArray(10) as Class1 'WithEvents doesn't work, so I don't
write it
End Class

So, what should I do from there to catch the events fired by class1 into
class2? I figured it could be with AddHandler, but I'd have to store the
index in Class1 and I don't want to do that if possible. If it's the only
way, I'll do it this way, but I want to know if there is a better way.

Thanks

ThunderMusic


Nov 21 '05 #2
You're right. Do it with AddHandler.
For the index problem, Write:
m_MyArray.Index Of(m_MyArray, sender)
In the sub where you catch the event.

"ThunderMus ic" wrote:
Hi,
I have a class let's say class1 that raises an event, let's say OnEvent.
In another class, let's say class2, I have an array of Class1. I want to be
able to trap the events fired by class1 within class2 and know (if possible)
the index of the class1 that fired the event. Is there a way? because
withevents does not work.

Here is some code you could rely on if you don't understand what I just
explain :

Class Class1
public event OnEvent()
End Class

Class Class2
private m_MyArray(10) as Class1 'WithEvents doesn't work, so I don't
write it
End Class

So, what should I do from there to catch the events fired by class1 into
class2? I figured it could be with AddHandler, but I'd have to store the
index in Class1 and I don't want to do that if possible. If it's the only
way, I'll do it this way, but I want to know if there is a better way.

Thanks

ThunderMusic

Nov 21 '05 #3
thanks for the quick answer

"Amiram Korach" <Am**********@d iscussions.micr osoft.com> a écrit dans le
message de news:49******** *************** ***********@mic rosoft.com...
You're right. Do it with AddHandler.
For the index problem, Write:
m_MyArray.Index Of(m_MyArray, sender)
In the sub where you catch the event.

"ThunderMus ic" wrote:
Hi,
I have a class let's say class1 that raises an event, let's say OnEvent. In another class, let's say class2, I have an array of Class1. I want to be able to trap the events fired by class1 within class2 and know (if possible) the index of the class1 that fired the event. Is there a way? because
withevents does not work.

Here is some code you could rely on if you don't understand what I just
explain :

Class Class1
public event OnEvent()
End Class

Class Class2
private m_MyArray(10) as Class1 'WithEvents doesn't work, so I don't
write it
End Class

So, what should I do from there to catch the events fired by class1 into
class2? I figured it could be with AddHandler, but I'd have to store the index in Class1 and I don't want to do that if possible. If it's the only way, I'll do it this way, but I want to know if there is a better way.

Thanks

ThunderMusic

Nov 21 '05 #4
ok, but I'd still have to use the AddHandler instead of WithEvents. I'm I
right?

thanks for quick answer
"Samuel R. Neff" <bl****@newsgro up.nospam> a écrit dans le message de
news:7l******** *************** *********@4ax.c om...

You can store the array of classes in a SortedList and use IndexOfKey
to determine the index of the class when the event is broadcasted.

Or you can use a third class that just stores the index and proxies
the event along with the index.

HTH,

Sam
On Mon, 24 Jan 2005 16:01:29 -0500, "ThunderMus ic"
<NO*******@symp atico.caSPAMATA LL> wrote:
Hi,
I have a class let's say class1 that raises an event, let's say OnEvent.In another class, let's say class2, I have an array of Class1. I want to beable to trap the events fired by class1 within class2 and know (if possible)the index of the class1 that fired the event. Is there a way? because
withevents does not work.

Here is some code you could rely on if you don't understand what I just
explain :

Class Class1
public event OnEvent()
End Class

Class Class2
private m_MyArray(10) as Class1 'WithEvents doesn't work, so I don't
write it
End Class

So, what should I do from there to catch the events fired by class1 into
class2? I figured it could be with AddHandler, but I'd have to store the
index in Class1 and I don't want to do that if possible. If it's the only
way, I'll do it this way, but I want to know if there is a better way.

Thanks

ThunderMusic

Nov 21 '05 #5

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

Similar topics

2
1180
by: Gonçalo Boléo | last post by:
I wan't to make a class that as a property that references a textbox and then cath the events of the text box in the class. In VB6 i make something like this: Dim WithEvents m_oTxt as VB.Textbox Property Let .... Property Set .... And then simply had events for the m_oTxt variable
4
8876
by: PiedmontBiz | last post by:
Greetings I have written an online survey with 110 questions. I use javascript to cycle thru all the questions which are displayed in an iframe. I keep track of the question number using a "global" variable. When testing it, everything works fine until I hit the back button. The iframe goes to the previous question, but of course, the counter is not decremented. Example if I am at question # 5 and I hit the back button, I go to #4,...
4
4096
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from the "EventLog" object in the "System.Diagnostics" namespace. When a certain event occurrs, both a WMI event is raised, and an event log entry is written. The problem I have is that I need to capture both events and somehow correlate which WMI...
11
1522
by: John Salerno | last post by:
My general problem with events seems to be that there are so many parts to them, and I'm not sure where they all go or when you use which parts. For example, there's the delegate, the event name, the event handler, then the coding that wires it together. For the most part, I do understand these things, but I get confused when it comes to putting it all together. More specifically, here's some code from a book: ...
16
1231
by: Tym | last post by:
I have a piece of code thus: For iLOOP = 0 To iNoDays - 1 For jLOOP = 0 To iMaxPeriods - 1 iX = 10 + (iLOOP * (dCellWidth + 10)) iY = 10 + (jLOOP * (dCellHeight + 10)) + Me.Size.Height / 4 If jLOOP = 0 And iLOOP = 0 Then lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) = New TextBox
4
2146
by: Joergen Bech | last post by:
Just out of curiosity: What is your favorite method of making sure that anything that happens on a form, only happens in response to a single, external event? Take the example below. I have made it as simple as I could: Put two textboxes on a form, paste the code and run it. The idea is that whatever is typed in one box is displayed in the other box, only reversed. This is a simple example of two repre- sentations of the same data on...
0
13100
ADezii
by: ADezii | last post by:
Not all ADO Power Users realize that there are Events, specifically related to the Connection and Recordset Objects, for which they can write code for. If one is aware of these Events, it is not exactly intuitive as to how you would access them. Below, please find a listing of Events which are exposed by the ADO Recordset and Connection Objects. I will also demonstrate the mechanism by which you, the ADO programmer, can make use of these...
7
3425
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the difference between events and delegates. Are they redundant features? How do I decide which to use? ...
1
4911
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
0
9735
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
10672
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...
0
10408
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9225
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7687
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
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
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.