Results 1 to 5 of 5

Thread: PROCEDURE TO CLOSE (UNLOAD) FORMS ?????

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Houston, TX - USA
    Posts
    21

    Post

    I have an application under development structured as follows:

    Form1 - Welcome splash
    Form 2 - General Description
    Form 3 - Detail 1
    Form 4 - Detail 1.1
    ...
    Form n - Detail 1.1...n

    Users will browse in the following sequence:

    Form 1 -> Form2 -> ......-> Form n

    Concerned with the number of forms that might be opened at the same time (the application will be a very large product catalog), and also concerned with possible memory limitations at the user's machine, I decided that only two forms should be open at the same time:

    Form1 - to which a user can return, via a menu placed in the other form being displayed at a given moment, and

    Form n - which is where the user is at that given moment.

    All other forms shall be unloaded, thus freeing memory.

    I wrote the following code:
    ___________________________________
    Public Sub UnloadNotCurrentForms()
    Dim NotCurrentForm As Form
    Dim FormName As String
    'INITIATE FOR ... NEXT PROCEDURE
    For Each NotCurrentForm In Forms
    FormName = UCase(NotCurrentForm.Name)
    Select Case FormName
    'KEEP CURRENTFORM OPEN
    Case "FORM1"&".frm", "FORMN"&".frm"
    'UNLOAD ALL OTHER FORMS & SET THEM = NOTHING
    Case Else
    Unload NotCurrentForm
    Set NotCurrentForm = Nothing
    End Select
    Next NotCurrentForm

    End Sub
    ______________________
    Please realize that:

    1- This code exists in each form
    2- "FORM1" & ".frm", "FORMN" & ".frm" are, respectivelly, the Splash form and the form at which the user is when "Formn" is shown.

    Although I can run the program while in programmimg mode, as well as after I create the executable, clicking Alt+Tab in W95 let me see that ALL forms previously seen remain open.

    In other words, no forms are unloaded or set to Nothing with my code.

    I also tried the code:

    Case "FORM1", "FORMN"

    that is, eliminating the attribute ".frm"

    Would anybody tell me what am I doing wrong, please



    ------------------
    Paul Stermann
    DSI-Houston

  2. #2
    Guest

    Post

    try:

    NextForm.show 'shows the following form before unloading the current one
    dim myform as form
    for each myform in app.forms
    if myform '??? put code here to determine that the user is NOT using it.
    ...then
    unload myform
    end if
    next myform


    this code makes sure that there is only 1 form open at a time.

    mail me for deeper explanation if you want it


    ------------------

    Wossname,
    Email me: [email protected]


    [This message has been edited by wossname (edited 11-06-1999).]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Houston, TX - USA
    Posts
    21

    Post

    Dear Wossname:

    Thank you for your code.

    may I assume that the problem with my code is that, instead of

    For Each NotCurrentForm In Forms

    I should write:

    For Each NotCurrentForm In App.Forms???

    I posted it here so others can see your solution as well

    Thanks



    ------------------
    Paul Stermann
    DSI-Houston

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Houston, TX - USA
    Posts
    21

    Post

    I understand that unloading the non-used forms is not enough to free memory, Should I still Set Forms = Nothing?

    ------------------
    Paul Stermann
    DSI-Houston

  5. #5
    Guest

    Post

    your partly right, the CODE of the form stays in memory, Set... = nothing will simply remove the name of the form from the form, so youll have a load of miscellaneous code floating around in memory!

    if anyone knows better please jump right in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width