-
January 29th, 2009, 10:39 AM
#1
Still my program is running :(
Hai pals,
Even after executing the code this code, my application exe is still running in the task manager?
Code:
Option Explicit
Private Sub cmdExit_Click()
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
Unload frm
Set frm = Nothing
End If
Next
Unload Me
End Sub
what can be the problem?
"Don't Bring A Knife To A Gun Fight"
-
January 29th, 2009, 11:24 AM
#2
Re: Still my program is running :(
Leaving OBJECTS open (not set to NOTHING explicitly)
Calling ANY form property after that code.
We'd have to see more...
-
January 29th, 2009, 11:32 AM
#3
Re: Still my program is running :(
Originally Posted by dglienna
Leaving OBJECTS open (not set to NOTHING explicitly)
Calling ANY form property after that code.
We'd have to see more...
ahaaa, let me chk.
"Don't Bring A Knife To A Gun Fight"
-
January 29th, 2009, 04:36 PM
#4
Re: Still my program is running :(
Try moving the code to the Unload Event instead of from a command button.
-
January 29th, 2009, 04:52 PM
#5
Re: Still my program is running :(
no tom,
it just the system tray program exit menu item. btw, i am keep chcking for any objects not destroyed.
"Don't Bring A Knife To A Gun Fight"
-
January 29th, 2009, 05:36 PM
#6
Re: Still my program is running :(
If you don't mind being a little messy . . . Put an "End" Statement after your loop. That oughta shut her down.
-
January 29th, 2009, 07:10 PM
#7
Re: Still my program is running :(
That's WRONG. END should NEVER be used. It is old, from the DOS days, when full-screen apps wouldn't shut down. END still leaves open files open.
-
January 29th, 2009, 08:34 PM
#8
Re: Still my program is running :(
I would not say that end should never be used. There is no problem using it but one should clean up the proper way before hand even if the End statement is used. End will terminate the app and in most cases there are no adverse side effects. Now of course if you leave files open and dlls initialized there could possibly be an issue but even then in most cases they are terminated by the end statement pending data will likely be lost but that is about it.
As for why the app is not shutting down my guess would be due to code located in a module or class that is part of your project. The end statement should terminate the process but would be better to look for the real problem.
I woudl check modules,classes, the unload event in each form, check the form area declarations for vars defined as public which may be accessed in a module and things such as this.
-
January 29th, 2009, 10:57 PM
#9
Re: Still my program is running :(
very useful information i got !
"Don't Bring A Knife To A Gun Fight"
-
January 29th, 2009, 11:39 PM
#10
Re: Still my program is running :(
Code:
Option Explicit
Public xlAppTemp As Excel.Application
Public xlWorkBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Dim strDate$
Public Sub GenerateReport()
On Error GoTo ErrHandler
' Creating Object for Excel File.....
Set xlAppTemp = New Excel.Application
' Making it Invisible and non-Interactive.....
xlAppTemp.Visible = False
xlAppTemp.DisplayAlerts = False
' Opening Template Excel File.....
Set xlWorkBook = xlAppTemp.Workbooks.Open(App.Path & "\Book1.xls", , False)
Set xlSheet = xlWorkBook.Sheets(1)
' Making Active to Worksheet 1.....
xlSheet.Activate
' END ' Let's put END here. Think EXCEL will end also?
' I am doing lot of things in it, but to provide you with example
xlSheet.Cells(15, 1) = "This is my report 1"
' Formating Date to attach with new file name.....
strDate = Format(Date, "yyyy-mm-dd")
' Saving excel file with new name on different folder.....
xlWorkBook.SaveAs App.Path & "\Output" & strDate & ".xls"
Cleanup:
' Destroying Objects.....
Set xlSheet = Nothing
xlWorkBook.Close SaveChanges:=False
Set xlWorkBook = Nothing
'The Visible and DisplayAlerts settings should be reset, as they can affect 'manual' use of Excel too.
xlAppTemp.Visible = True
xlAppTemp.DisplayAlerts = True
xlAppTemp.Quit
Set xlAppTemp = Nothing
Exit Sub
ErrHandler:
'I presume this section comes after ErrHandler, in which case you will want to close the workbook without changes.
'(save happens just above if no error occurs)
xlWorkBook.Close SaveChanges:=False
Set xlWorkBook = Nothing
'The Visible and DisplayAlerts settings should be reset, as they can affect 'manual' use of Excel too.
xlAppTemp.Visible = True
xlAppTemp.DisplayAlerts = True
xlAppTemp.Quit
Set xlAppTemp = Nothing
End Sub
Private Sub Command1_Click()
Call GenerateReport
Beep
End Sub
-
January 30th, 2009, 12:32 AM
#11
Re: Still my program is running :(
xlSheet.Activate
' END ' Let's put END here. Think EXCEL will end also?
No. I would say that it will not. but then here you are activating another program and should not expect the end statement to terminate the external executable(s).
That is not to say that end does not have its uses. As with all tools they are good for some things and not for others. One must no where and when to use them and what to expect when they are used.
In this case the program that you have written should terminate completely but will leave Excel running as should be expected and in rare cases maybe even the desired effect.
That said I rarely use such coding practice. I do not like the idea of forcing my users to purchase excel or other third party programs to use my software. It has its place but you also must realize there are special requirements when you use these techniques that are outside of the VB environment.
-
January 30th, 2009, 01:56 AM
#12
Re: Still my program is running :(
But, called enough times in a row is a guaranteed way to run out of memory.
An instance of Excel is created, and it's under program control to terminate it properly. That is the ONLY way to release the memory it's using.
-
January 30th, 2009, 02:37 AM
#13
Re: Still my program is running :(
You say "it just the system tray program exit menu item. btw, i am keep chcking for any objects not destroyed."
Do you mean you are exiting the program from a pop-up menu from the system tray? If that is the case you still should put the unload forms code in the Unload Event. Try it.
I apologize if I misunderstood.
-
January 30th, 2009, 03:16 AM
#14
Re: Still my program is running :(
Originally Posted by dglienna
But, called enough times in a row is a guaranteed way to run out of memory.
An instance of Excel is created, and it's under program control to terminate it properly. That is the ONLY way to release the memory it's using.
Yes of course, but this is not the purpose of the end statement. There is a specific statement to terminate the external instance of the other program you have started in this case. In other cases there may be no direct method to shut down the other program. Shell to a dos program for example.
BTW one can always simply close excel manually at any point.
The point is that just because the End statement does not terminate external programs launched by your code does not mean that it should never be used. That's kinda like saying one should never use the unload function because it does not unload the entire app or not use the print function because it does not cause a word document to print on a different pc. Or you could say that one should never use the excel functions or word or access because they don't terminate when your application is closed.
The fact is the End does exactly what it should. It ends your program execution. It is up to the programmer to make sure that the program is ready to be ended at this point but the VB environment does handle many oversights by the programmer as well as many bad programming techniques to result in a clean exit in most cases. It was never intended to end other programs.
-
January 30th, 2009, 05:31 AM
#15
Re: Still my program is running :(
I had one app which would terminate just fine on most machines, but not all. It was a simple app, with only one form. After exhausting all options, I used the End statement after Unload Me, and that solved it. I think that was with winME though, but it just shows that it is possible to have an app not fully unload even when you're code is perfectly fine.
So if you're properly unloading everything, I see nothing wrong with using the End statement. It's just one of those things which we normally wouldn't need, sorta like the Call, Let, and GoTo statements.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|