Solved

Moving ALL of Form's procs into Module Save Mem?

Posted on 1999-01-19
4
142 Views
Last Modified: 2010-05-03
I am interested in making a program that can create tons of instances of a particular form. I do this like so:

Dim MyFormInstances() as Form1

Redim MyFormInstances(10)
Set MyFormInstances(0) = New Form1

In Form1 i have TONS of procedure calls: some my own, some "events" that i am handling. I was wondering though, if i am creating several nstances of the same form ("Form1" in this case) would each of these procedures that were inside the form1 be duplicated into each of these instances?  If so wouldnt this mean each instance would continue to use more and more memory?

If so then would it be wiser to rewrite and move ALL of my procedures (and functions) that exist in the Form1 into a Module and pass to the module's proc's/func's the Form who is requesting the information..Like this:

----
FORM1 CODE:

Public MyValue as integer

private sub FORM1_CLICK()
  'Me is VB's term for the current form -- in this case, the instance
  Call Module_FORM1_CLICK(Me)
end sub

------
MODULE CODE:

public sub Module_FORM1_CLICK(Form as Form1)
  Form.MyValue = 1
end sub

----

I would do this with EVERY procedure that existed inside FORM1. I know this wouldn't eliminate the possibilty of using more and more memory but at least (as it appears) it will reduce it significantly.  PLEASE LET ME KNOW IF THIS IS CORRECT or if Windows handles this.  Please explain in detail please.  
0
Comment
Question by:ljaques
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1469473
There is a certain amount of over-head associated with each instance of a form.  Memory consumption on multiple instances of a form is more dependent on the number of controls on the form rather than the underlying code.  The Code is loaded into memory as it is executed.  If you have a lot of form level variables, it could become more intensive with each new instance.

Instead of using your own array (MyFormInstances())

Try declaring a new instance like this:

Dim moForm1 As Form1
   
Set moForm1 = Forms.Add("Form1")
moForm1.Visible = True

You can then refer to the VB forms collection:

MsgBox Forms.Count
MsgBox Forms(0).Caption




0
 
LVL 10

Accepted Solution

by:
caraf_g earned 20 total points
ID: 1469474
I wouldn't recommend doing what you're thinking of doing - it goes against all proper "object - oriented" design.

Just imagine the sort of trouble you're getting yourself into: you will no longer be able to access any of your form's Private variables, procedures and properties, for starters.

Even if you wanted to access your form's Public vars etc, you will have to modify each and every procedure so that you pass in an extra parameter as an object variable so that you can pass in Me when you call it from your form.

Finally, for dealing with Object type variables you are probably better off using a Collection rather than an array.

0
 

Author Comment

by:ljaques
ID: 1469475
So, by using the Collections object i can save MASSIVE amounts of memory or is it just a good way of keeping things organized?!?
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1469476
You won't be able to save massive amounts of memory and your solution causes more problems than it will solve.

Using a collection is just a good way of keeping things organised.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change vba from autofit to 13.5 width? 4 29
String manipulation in Visual Basic 7 73
Adding to a VBA? 6 78
MS SQL Update query with connected table data 3 41
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

820 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