Solved

Working with forms

Posted on 2000-04-21
9
120 Views
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 xxxform.show 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?
Thanks
Jeff Scharpf
0
Comment
Question by:jscharpf
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 44

Expert Comment

by:bruintje
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

:O)Bruintje
0
 
LVL 12

Expert Comment

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

M
0
 

Author Comment

by:jscharpf
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!

0
 
LVL 28

Expert Comment

by:AzraSound
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.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Expert Comment

by:toys032498
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.  

Anthony
0
 
LVL 12

Accepted Solution

by:
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.

M
0
 

Author Comment

by:jscharpf
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
Jeff
0
 
LVL 28

Expert Comment

by:AzraSound
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.
0
 
LVL 12

Expert Comment

by:mark2150
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.

M
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now