Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Declaring Withevents array

Posted on 2002-07-26
7
Medium Priority
?
874 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 300 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

Independent Software Vendors: 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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

688 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