Working with forms

Posted on 2000-04-21
Last Modified: 2010-05-02
I have a general question regarding forms. I have a program that opens up several forms with many controls on each. I have one form with several buttons that sits at the bottom of the screen. The use clicks on one of these buttons to show one of the forms. Currently I load all the forms at startup and when the user clicks a button below, it just does a for that form, bringing up that particular form. Is this a very efficient way of doing this? I dont want to load/unload each form each time, as this seems to take too much time. Also some forms contain controls that I'm using regardless of which form I'm showing, so I need access to them. Am I asking for trouble keeping all these open? Is there a better way to do this?
Jeff Scharpf
Question by:jscharpf
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
  • 3
  • 2
  • 2
  • +2
LVL 44

Expert Comment

ID: 2737599
well depends, if your audience all have decent pc's that can handle the load why not?

but it's indeed memory intensive, maybe you can build the other forms in some sort of sharing composition, where you just change several frames on a form that contain various compositions of controls instead of loading a complete form for each composition...a bit more trouble with bulding, because you have to keep count of several layers but maybe more efficient....just a thought

LVL 12

Expert Comment

ID: 2737638
You'ld be better off loading and unloading the forms instead of loading all at once and then just using .Show.


Author Comment

ID: 2737714
If I load and unload, doesn't it take more time? I will try that. The one problem is that some forms contain controls that I use even if I'm on another form. I thought maybe there was a way to "hide" a form where it's controls were still accessable (say a text box or comm control) but it would be somehow not using as much memory. I guess that does sound pretty stupid now that I think of it,lol.
I will try loading and unloading..Otherwise it's time to buy more ram!

Industry Leaders: 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!

LVL 28

Expert Comment

ID: 2737873
you might want to just hide and show each form setting its visible property to true and false as needed. the form isnt actually unloaded but you dont run a risk of the user doing anything.

Expert Comment

ID: 2738069
Why do you still need access to the form?  Why don't you just create a Module and hold the data there or create a Proberty Get, Let?  It is better to hide forms not needed from the user so they don't get confused.  Mark2150 is correct--> Just load the forms as they are needed, and only unload forms that are less likely to be used again.  

LVL 12

Accepted Solution

mark2150 earned 50 total points
ID: 2738316
Global vars are, to me, easier to manage and they don't have events associated with them. When you're loading and unloading forms and yet trying to depend on the values things can get messy. If you declare stuff PUBLIC in your module level code the vars will be visible everywhere.


Author Comment

ID: 2738347
Ok, I must clarify.
I'm kind of a dangerous beginner VB programmer,:)
I have built some stuff into a module, but other stuff I've put on forms. For example, I have 7 forms, each with some controls. On one of the forms I have a comm control that I use to communicate with instruments. THe operator may click a button to bring up another form, and some operation might access that comm control (on the previous form which is now sitting in the background somewhere). I realize it wasn't the smartest way to do things at this point, but I'm leary of rewriting the whole thing unless I have to. Does hiding the form help at all with memory management? The more I think about it, the more I need to revisit the whole thing,lol!
Just looking for as many ideas as I can get, and so far you've all helped..

I will just give the points to Mark2150 if thats ok..
Any additional comments are appreciated.

Thanks again
LVL 28

Expert Comment

ID: 2738372
if you have any custom procedures or functions that numerous forms may call then you should always put them in a module.  that way if for some reason you ever remove a form for any reason, you dont have to worry about rewriting any of those functions.  as far as hiding a form, it helps only in that you dont waste time loading and unloading forms.  it will take up the allotted amount of memory to load all the forms initially. this obviously takes up more memory than if you only have a couple forms open and are using loading and unloading accordingly.  however it will improve speed since it doesnt have to load and unload forms continuously.  its really a judement call.
LVL 12

Expert Comment

ID: 2738373
Hiding the form doesn't save much in the way of memory.

Myself, I usually have a main form that I put the specialty controls on. So the MsComm control, timers, CommonDialog, Data, etc. are all on this one form that is never unloaded. My projects generally start with Sub Main() instead of any specific form. This is where I build my database connections, pull in any registry entries I need, etc.

Once I'm up and running at the module level I hand off to the master form and things get rolling. From the master form all child forms are loaded/unloaded as needed. This is (marginally) slower than leaving the forms in memory, but if your task switch is only done occassionally then this is not really an issue.

The module level code also has my sharable routines, shutdown code, etc.

The child forms are invoked on demand. If they need data they can either use a nice global from the module or they can rely on the one master form. Beyond that they're on their own.

This vertical heirarchy keeps my forms from crosstalking and also keeps a lid on memory usage.


Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 76
vb6 connector to SQL Server 2 42
Excel Automation VBA 19 116
Excel 2007 Random Generate List Based on Defined Source Cells 3 32
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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

752 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