Solved

Working with forms

Posted on 2000-04-21
9
121 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

948 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

22 Experts available now in Live!

Get 1:1 Help Now