Solved

VB.NET - 'WithEvents' variables cannot be typed as arrays - Now what?

Posted on 2008-10-17
4
803 Views
Last Modified: 2012-05-05
I have a class that I want to use several instances of... the class raises events to notify me of completed things.

everything works fine as 1 instance... however if i try to make an array of the class i get the error:

 'WithEvents' variables cannot be typed as arrays

is there a better way to do this?
0
Comment
Question by:mcainc
  • 2
4 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
Comment Utility
Can you show the relevant code?
0
 

Author Comment

by:mcainc
Comment Utility
Private WithEvents client() As IRCClient

this gives the error

Private WithEvents client As IRCClient

this works fine
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
Comment Utility
mcainc

You'll have to use a collection of your objects, then use AddHandler on each item in the collection to handle each objects events.

Wayne
0
 
LVL 27

Accepted Solution

by:
Dabas earned 500 total points
Comment Utility
Hello mcainc,

The way to overcome this is as per snippet

Regards,

Dabas
Private WithEvents client As IRCClient 
Private ClientArray() as IRCClient 
Somewhere else in your code, you might have something like: 
For Each client in ClientArray
...Raise your events here for the single client within the array
Next 
 

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now