Solved

Declaring Withevents array

Posted on 2002-07-26
7
869 Views
Last Modified: 2007-11-27
What i am trying to do is make an array of one form that i have made and have the events fire on the array. is there a way to declare an array withevents?
0
Comment
Question by:sk33v3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:ventond
ID: 7180678
Arrays don't have events. If you could do WithEvents on an array, there wouldn't be any. But you can't.

Clarify what you are trying to do here.
0
 

Expert Comment

by:paulll
ID: 7180679
I think you would have to create or use an object that has events as an object array and use its properties to store array values (maybe in the Tag property)and get your events from existing events for the objects.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7180710
you could declare something like this:

dim withevents myvar as sometype
dim myvar2(2) as sametype

set myvar = myvar(1)




0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 9

Author Comment

by:sk33v3
ID: 7181191
Ok i have a form that i need the events to be present on that i am making an array of.

dim myform1(0 to 30) as frmMyform

when i try to do the private withevents instead of dim it doesn't work. I need to find a way to get the events to be present.
0
 
LVL 2

Accepted Solution

by:
ventond earned 75 total points
ID: 7181452
Doesn't work exactly like you are hoping however you are close.

The Form is an object. When you write events in that object, every instantiation of the object has those events. There is no WithEvents on said object, because the events are in the object.

Code example:
(frmMain) (General Decs)
Dim myform1(0 to 30) as frmMyform

(form load click event)
for x = 0 to 30
   set myform1(x) = new frmMyform
   load myform1(x)
   myform1(x).show
next


Now, when you run your program you should have 32 windows open. 1 frmMain, 31 copies of frmMyform. A couple of things, make sure that frmMyform never references itself by name. (Always use the Me reference.) If you use the debugger you will find that each of your copies of frmMyform all call the same code.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7181484
In order to require the use of WithEvents, I have to assume that your form object actually raises the events and is not merely the container for event raising controls.  If that is the case, you have found out that object arrays cannot be declared withevents.  

On Karl Peterson's page:
http://www.mvps.org/vb/

You'll find this sample project:
http://www.mvps.org/vb/code/ObjArrays.zip

It shows some workarounds for this problem...
0
 
LVL 9

Author Comment

by:sk33v3
ID: 7182013
Fantastic that was exactly what i was looking for. Thanks alot.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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