Solved

Declaring Withevents array

Posted on 2002-07-26
7
862 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
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library 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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now