Solved

Declaring Withevents array

Posted on 2002-07-26
7
865 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 59
SQL VB connection works in one PC and doesn't in another 15 64
using web browser with BING 40 119
Sub or Function is not defined 6 26
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…

808 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