Solved

Difference of following ....

Posted on 2004-04-29
4
395 Views
Last Modified: 2012-06-21
Can anybody tell me the difference between the following:

1) form1_terminate
    form1_unload

2) form1_initialize
    form1_load

3) set object1 = nothing
    object = NULL
0
Comment
Question by:lenzge
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
Load: Use the Form_Load event for initialisation. Initialisation means things you want to have ready before using the Form, such as fill up a combo box with data, assign initial values to certain variables.
When the program starts up, it runs the Sub Main from the Basic Module or load a Form of your choice. Use the Menu Command Project | Properties (Click Tab GENERAL) to select the start up Form or Sub Main:
While running the application, you can get the application out of sight by using the Hide method, and bring it back with the Show method. Hide/Show does not affect the status of the form at all because the form is already there.
You can remove the form completely from the memory by using the Unload method, then bring it back again with the Show method. This time the Show method implies a Load action plus the normal Show action (similar to the case Hide/Show), i.e. the Form is initialised by the Load action.
Sometime you want to do some initialisation on the controls of the form before presenting it to the world. In that case do a Load, do all the necessary initialisation then Show the form.
Note that while you are inside Sub Form_Load the Form is not yet existent. Therefore you cannot execute a Setfocus of a control of the form while that form is being loaded. One way to get around it is to Enable a Timer to schedule that Timer to run in 300ms (i.e. delaying the SetFocus action until the Form becomes existent).
If you want to define the start up position of a Form (i.e. where the Form appears on the screen when it first shows up at run-time) use the Form Layout Window to do that.
Activate: use Form_Activate to update certain things each time the form is revisited. It’s similar to initialisation in Form_Load, except that Form_Load is called only once at loading whereas Form_Activate is called every time the Form becomes active (i.e. regaining the focus).
Unload ' use to tidy up loose ends before leaving. Sometimes, it’s better to use Form_QueryUnload as it returns UnloadMode which tells you how the unload was initiated (i.e. by user, by other program etc..). Then you can decide to stop the Form unload process by setting Cancel to True.
 
Left, Top: X,Y coordinates of Form relative to the Top Left corner of the screen. You can set these values in Form_Load.
Width, Height : Size of Form including Border. Use ScaleWidth and ScaleHeight to refer to the form size without border.
WindowState : You use it to indicate the start up state of the Form. It’s either Normal (as you had it at design time), Minimised (Iconised) or Maximised (take the whole screen).
A form can be run in either Modeless or Modal mode.
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 50 total points
Comment Utility
I tried to explain the best I could

1) form1_terminate
    form1_unload

    Basically Terminate refers to the program, unload can be called if another program Unloads the object Form1.


2) form1_initialize
    form1_load

    Form1 initalize is only called when the form is initalized, so if another form Loads the Object Form1, form1_load will be called.

3) set object1 = nothing
    object = NULL

   Set Object = nothing is basically clearing the memory
   object = NULL <--- NOT EVEN VALID VB Code
   
0
 

Author Comment

by:lenzge
Comment Utility
Sorry, clarification for no. 3:

i) set object_abc = nothing

ii) if (object_abc = NULL) then
       (action code's here)
    end if

When the second case will return a true value?
0
 

Author Comment

by:lenzge
Comment Utility
Oops, I made a mistake on #3 and now I know what's wrong about it now. Thanks to all of you.
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

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 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…
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…
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now