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
Solved

Declaring Withevents array

Posted on 2002-07-26
7
866 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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