Difference of following ....

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

1) form1_terminate

2) form1_initialize

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

Expert Comment

ID: 10956481
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.
LVL 19

Accepted Solution

BrianGEFF719 earned 50 total points
ID: 10956997
I tried to explain the best I could

1) form1_terminate

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

2) form1_initialize

    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

Author Comment

ID: 10974849
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?

Author Comment

ID: 10993568
Oops, I made a mistake on #3 and now I know what's wrong about it now. Thanks to all of you.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

679 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