Solved

Difference of following ....

Posted on 2004-04-29
4
397 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
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.
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 50 total points
ID: 10956997
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
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?
0
 

Author Comment

by:lenzge
ID: 10993568
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 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…
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…

822 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