473,386 Members | 1,973 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,386 software developers and data experts.

Dim withevents - array of classes

Hi all

I googled some and found that I can no longer - dim withevents myclassname()
I also understand that I can use addhandler...
But... what if I do not know the amount of classes that will be created ?....

What am I trying to do:
I have a process that scans a directory for files tranxxxxx.txt
for each transaction file I want to create a clsTransactionHandler
the class will read the file, process it, store it where it should etc etc
for each class the process needs to know when it is done (to notify the
user)...

Please advise

TIA
Guy Cohen
Dec 27 '07 #1
4 2746
You can no longer ...?

You never could - In VB.NET that is.

Add the handler (using AddHandler) at the point where you instantiate the
class object.
"Guy Cohen" <Gu******@discussions.microsoft.comwrote in message
news:29**********************************@microsof t.com...
Hi all

I googled some and found that I can no longer - dim withevents
myclassname()
I also understand that I can use addhandler...
But... what if I do not know the amount of classes that will be created
?....

What am I trying to do:
I have a process that scans a directory for files tranxxxxx.txt
for each transaction file I want to create a clsTransactionHandler
the class will read the file, process it, store it where it should etc etc
for each class the process needs to know when it is done (to notify the
user)...

Please advise

TIA
Guy Cohen
Dec 27 '07 #2
I was talking about vb6 :)
Can you please show me the correct way in vb.net ?

"Stephany Young" wrote:
You can no longer ...?

You never could - In VB.NET that is.

Add the handler (using AddHandler) at the point where you instantiate the
class object.
"Guy Cohen" <Gu******@discussions.microsoft.comwrote in message
news:29**********************************@microsof t.com...
Hi all

I googled some and found that I can no longer - dim withevents
myclassname()
I also understand that I can use addhandler...
But... what if I do not know the amount of classes that will be created
?....

What am I trying to do:
I have a process that scans a directory for files tranxxxxx.txt
for each transaction file I want to create a clsTransactionHandler
the class will read the file, process it, store it where it should etc etc
for each class the process needs to know when it is done (to notify the
user)...

Please advise

TIA
Guy Cohen

Dec 27 '07 #3
On Wed, 26 Dec 2007 22:13:01 -0800, Guy Cohen
<Gu******@discussions.microsoft.comwrote:
>Hi all

I googled some and found that I can no longer - dim withevents myclassname()
I also understand that I can use addhandler...
But... what if I do not know the amount of classes that will be created ?....

What am I trying to do:
I have a process that scans a directory for files tranxxxxx.txt
for each transaction file I want to create a clsTransactionHandler
the class will read the file, process it, store it where it should etc etc
for each class the process needs to know when it is done (to notify the
user)...

Please advise

TIA
Guy Cohen
Dim list As New List(Of clsTransactionHandler)
Dim cls as clsTransactionHandler

' For each class that you instantiate:
cls = New clsTransactionHandler
AddHandler cls.SomeEvent, AddressOf SomeEventHandler
list.Add(cls)
Private Sub SomeEventHandler()
....
To prevent leaking memory, be sure to call RemoveHandler when you free
each clsTransactionHandler object.
Dec 27 '07 #4
Another way in additon to what others have suggested is create a custom
collection instead of an array that will funnel and raise the events
Look up how to create a custom collection class
(http://visualstudiomagazine.com/feat...orialsid=1329).

That way you could use
Dim WithEvents myCol As New MyCollection

The collection class would look something like this
(not complete)
Public Class MyCollection(Of T)
Inherits System.Collections.CollectionBase

Public Event MySpecialEvent(ByVal sender As Object, ByVal e As
EventArgs)

Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal
value As Object)
AddHandler value.MySpecialEvent, AddressOf HandleMySpecialEvent
MyBase.OnInsertComplete(index, value)
End Sub

Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal
value As Object)
RemoveHandler value.MySpecialEvent, AddressOf HandleMySpecialEvent
MyBase.OnRemoveComplete(index, value)
End Sub

Private Sub HandleMySpecialEvent(ByVal sender As Object, ByVal e As
EventArgs)
'Bubble up the event
RaiseEvent MySpecialEvent(sender, e)
End Sub
End Class

"Guy Cohen" <Gu******@discussions.microsoft.comwrote in message
news:29**********************************@microsof t.com...
Hi all

I googled some and found that I can no longer - dim withevents
myclassname()
I also understand that I can use addhandler...
But... what if I do not know the amount of classes that will be created
?....

What am I trying to do:
I have a process that scans a directory for files tranxxxxx.txt
for each transaction file I want to create a clsTransactionHandler
the class will read the file, process it, store it where it should etc etc
for each class the process needs to know when it is done (to notify the
user)...

Please advise

TIA
Guy Cohen
Dec 29 '07 #5

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

Similar topics

2
by: Jakob Bengtsson | last post by:
Hi, I have a form (which cannot be serialized). In the form's code I declare an object like this (never mind the object nor class name, it's for illustration only): Private WithEvents...
1
by: Rob Smeets | last post by:
Hi you Gurus, I would like your help with my 'challenge' ;-) Any help or advice would be greatly appriciated!! I've created a Class wich retrieves FTP files. In that Class there are several...
4
by: Brian Lowe | last post by:
I have several aspx pages that include a couple of asp:placeholder controls, an example is myPage.aspx. The page inherits from a custom class 'myClass' which inherits System.Web.UI.Page which...
3
by: Terry Olsen | last post by:
I want to have an array of class objects that raise an event when a condition is true. Like so... ------------------------------------------------------- Public Class ClientHandler Public...
7
by: Rob Nicholson | last post by:
A thought - has VB.NET been extended to be able to handle arrays or collections with events? A problem with VB6 was that you could only declare: Private WithEvents MyControl As MyControl ...
2
by: DiGa | last post by:
Hi all I have to write an application in VB.NET which monitors multiple files at the time and notifies the user about changes. I thought to use multiple instances of FileSystemWatcher in an...
1
by: Joel Whitehouse | last post by:
Is there any way I can get the effects of declaring objects using WithEvents while also having indexed addressing? I'm designing a control that has several buttons, the functions of which vary...
3
by: Craig | last post by:
In VB.net I am trying to make an array of dynamically generated buttons. I can do that but I cant figure out how to get them to work "WithEvents." Can someone tell me if and how this can be done?...
3
by: Vemund Halvorsen | last post by:
Hi, Im having some trouble getting Addhandler to work. Using withevents everything is working fine. But with AddHandler I get no callback. The code below works fin if I declare _tcp as a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.