473,327 Members | 2,016 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,327 software developers and data experts.

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 1091

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, "ThunderMusic"
<NO*******@sympatico.caSPAMATALL> 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.IndexOf(m_MyArray, sender)
In the sub where you catch the event.

"ThunderMusic" 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**********@discussions.microsoft.com> a écrit dans le
message de news:49**********************************@microsof t.com...
You're right. Do it with AddHandler.
For the index problem, Write:
m_MyArray.IndexOf(m_MyArray, sender)
In the sub where you catch the event.

"ThunderMusic" 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****@newsgroup.nospam> a écrit dans le message de
news:7l********************************@4ax.com...

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, "ThunderMusic"
<NO*******@sympatico.caSPAMATALL> 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
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...
4
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...
4
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...
11
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,...
16
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...
4
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...
0
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...
7
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.