Results 1 to 22 of 22

Thread: Program Stays In Memory

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Program Stays In Memory

    Could someone be so helpfull as to look at my small program and see if they can figure out why Excel, and the program itself, resides in the task manager after everything is closed? I'm setting all the objects to nothing (I think) but it still doesn't work. Thank you in advance!
    Attached Files Attached Files
    Last edited by Esham; Oct 18th, 2005 at 02:53 PM.

  2. #2
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Program Stays In Memory

    You didn't include the form in the zip file.

    Are you calling "Unload"

    You need to call unload on each form

    VB Code:
    1. UnLoad Form1

    Of course, you can also just call end
    VB Code:
    1. End

    But I have learned that this can be bad.

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Program Stays In Memory

    And, in the form.unload code include the

    set form = nothing

    substitute the name of your form for "form"

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    Sorry, the new zip file has the form.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Program Stays In Memory

    You only incluided the .vbp file and not the frmSplash, FormMain.frm, & Module1.bas.

    Do not ever use End at all.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Program Stays In Memory

    I guess I didn't see where you set either form = nothing.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Program Stays In Memory

    If there is no error then your xlApp only gets Set to Nothing. It wont get .Quit. You need to either .Close or .Quit all your Excel object variables and then after that destroy them by setting them equal to nothing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Program Stays In Memory

    You haven't included the module, but I can see part of the problem - you are not closing Excel properly.

    In form load you should change this:
    VB Code:
    1. .Workbooks.Open "SOME DIRECTORY\OP Concerto Forecast.xls"
    2.     .Worksheets("Selection").Activate
    to this:
    VB Code:
    1. Dim xlWorkbook as Excel.Workbook
    2.     Set xlWorkbook = .Workbooks.Open "SOME DIRECTORY\OP Concerto Forecast.xls"
    3.     xlWorkbook.Worksheets("Selection").Activate
    4. End With
    5. With xlWorkbook.Worksheets("Selection")


    Then, remove the ".Quit" from the end of the With, and change the section from Done: onwards to this:
    VB Code:
    1. Done:
    2.     FormSplash.Hide
    3.     Set FormSplash = Nothing
    4.     xlWorkbook.close SaveChanges := False
    5.     Set xlWorkbook = Nothing
    6.     xlApp.Quit
    7.     Set xlApp = Nothing
    8.     Screen.MousePointer = 0
    9.     Exit Sub
    10. AdoError:
    11.     If Err.Number = 32755 Then
    12.         Resume Done
    13.     Else
    14.         MsgBox Err.Description, vbCritical, "Error #: " & Err.Number & Err.Source
    15.         Resume Done
    16.     End If

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    I've created over 50 other vbprojects and never set my startup form to nothing and none of those reside in memory. Any other ideas. I'll try and set both forms to nothing in the startup form unload event.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Program Stays In Memory

    The form object is not the problem. Excel remains running because just setting it to nothing will not quit the app and destroy it. Do you have any other excel object variables in the Module1.bas?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Program Stays In Memory

    Moved from Classic VB forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    Quote Originally Posted by RobDog888
    The form object is not the problem. Excel remains running because just setting it to nothing will not quit the app and destroy it. Do you have any other excel object variables in the Module1.bas?
    I do quit xlApp and then set it to nothing. I also have a chart object which I also set to nothing.

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Program Stays In Memory

    Esham,

    Your problem:
    VB Code:
    1. Done:
    2.     Unload FormSplash
    3. '    FormSplash.Hide
    4.     Set FormSplash = Nothing

    You hide the form but never unload it. Call a routine at the end of you program like such: (Place this in a module and call it from your forms Unload event.
    VB Code:
    1. Public Sub UnloadAll()
    2. Dim frm As Form
    3. Dim ctl As Control
    4.  
    5.     On Error Resume Next
    6.    
    7.     For Each frm In Forms
    8.    
    9.         For Each ctl In Controls
    10.             Set ctl = Nothing
    11.         Next
    12.        
    13.         Unload frm
    14.         Set frm = Nothing
    15.     Next
    16.  
    17. End Sub

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Program Stays In Memory

    I have a feeling that the code in the module (which isn't in the zip file) could be the cause of your program not closing.

    The changes I suggested above should correct the issue with Excel.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    The module1.bas should be in the zip file. I 've updated it. Check again. Sorry about that.

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Program Stays In Memory

    You should make similar changes to the CreateChart sub as I mentioned above.

    Also, you should not have object variables declared as "New" anything when they are public (and arguably not at all). You should add a line like this instead when you want the application to open (in form_load and CreateChart):
    Code:
    Set xlApp = New Excel.Application
    And Randem is correct about your splash form, you should be using the amended code as in his first example (or the other if you prefer).

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    VB Code:
    1. Public Sub UnloadAll()
    2. Dim frm As Form
    3. Dim ctl As Control
    4.  
    5.     On Error Resume Next
    6.    
    7.     For Each frm In Forms
    8.    
    9.         For Each ctl In [COLOR=DarkRed]Controls[/COLOR]
    10.             Set ctl = Nothing
    11.         Next
    12.        
    13.         Unload frm
    14.         Set frm = Nothing
    15.     Next
    16.  
    17. End Sub
    [/QUOTE]

    It gives me an error when I compile saying the variable is not defined.

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Program Stays In Memory

    I also noticed that in your formmain's unload event your calling itself to unload again in that procedure creating a circular reference.
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2. Unload FormSplash
    3. 'Unload FormMain 'Circular ref.
    4. Set FormSplash = Nothing
    5. Set FormMain = Nothing
    6.  
    7. End Sub
    Also, switch the event to the Form_QueryUnload event instead. In case your clicking the 'x' at the top right corner to close the app. it will be sure to close and destroy all objects.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Program Stays In Memory

    Esham,

    You did not state where you attempted to place the code or anything. The code does work I use it exactly as posted all the time. Did you place this code in a module?

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    Quote Originally Posted by randem
    Esham,

    You did not state where you attempted to place the code or anything. The code does work I use it exactly as posted all the time. Did you place this code in a module?
    Randem,

    I placed your exact code into the Module1.bas and called it from FormMain.QueryUnload. What am I doing wrong?

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3. Call UnloadAll
    4.  
    5. End Sub

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Re: Program Stays In Memory

    Everything seems to be working now except for the Controls unload loop. Thanks for all the help!

    randem,

    Any suggestions on why that's not working. The Forms unload works fine, just not the Controls.

  22. #22
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Program Stays In Memory

    It looks like a minor change is needed:
    VB Code:
    1. For Each ctl In [b]Frm.[/b]Controls

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