|
-
Mar 21st, 2000, 04:27 AM
#1
Thread Starter
Member
Hi,
I guess no one knows how to make a module that is running in the background close when windows shuts down. My program will not close when windows shuts down. It is a module, with no forms that runs in the background. All of my code is in the Sub Main(). I started with a form set to be invisible but then my code would not execute. So, I put it in a module, and it ran but would not close when windows shuts down (told my program was not respnding, have been told this is because vb does not understand what do when windows sends its shut down message). I have a loop in my program and would like it to end when windows shuts down. I have been told that I have to subclass, but I do not know how. I have posted many posts on this topic, with little success. So I thought I would give it one last try.
Thanks for all you help and understanding,
Kevin
-
Mar 21st, 2000, 04:47 AM
#2
I assume you use a loop in the sub main. I had a quick test, and it worked fine after I included a DoEvents in the loop.
-
Mar 21st, 2000, 05:54 AM
#3
Thread Starter
Member
Thanks,
I do have a Doevents in my loop and is still will not work. Here is my loop code:
Code:
Dim result As Integer
Dim tdFile As Integer
tdFile = FreeFile
Open "C:\Log.txt" For Append As tdFile
Do While Format(Now(), "h:mm am/pm") < Format("8:00 pm", "h:mm am/pm")
Call CheckKey
If Len(sString) = 50 Then
Print #tdFile, sString
sString = ""
DoEvents
End If
Loop
Thanks,
Kevin
-
Mar 21st, 2000, 06:22 AM
#4
transcendental analytic
Was you told not to do that? I have posted this maany times already: Do NOT use DOEVENTS with continuous loops. The simplest way to solve this problem is to add a form that will automatically on attemt to close, run the code in its Form_Unload event. There you should specify a condition that your loop in your Sub Main will end. Then set cancel=1 You also need to Unload the form once more and set a condition in Form_Unload that will skip the cancel and end.
Sounds too complicated? I hate this too
-
Mar 21st, 2000, 07:46 AM
#5
Thread Starter
Member
Ok, let me get this right.
my code would look some thing like this
Code:
Dim result As Integer
Dim tdFile As Integer
Dim unloadnow As Byte
tdFile = FreeFile
Open "C:\Log.txt" For Append As tdFile
Loop Until unloadnow
unloadnow = 1
Unload Me
Call CheckKey
If Len(sString) = 50 Then
Print #tdFile, sString
sString = ""
DoEvents
End If
Loop
Private Sub Form_Unload(Cancel As Integer)
If unloadnow < 2 Then
unloadnow = 1
Cancel = 1
End If
End
End Sub
Can I make my form invisible and still have the code execute??
Thanks,
Kevin
-
Mar 21st, 2000, 02:50 PM
#6
transcendental analytic
Easy thing: form.visible=false
-
Mar 21st, 2000, 04:06 PM
#7
Hyperactive Member
Kedaman:
"Was you told not to do that? I have posted this maany times already: Do NOT use DOEVENTS with continuous loops."
You have any special reason for stating that?
IMHO, loops that run longer then 10 times, and don't have doevents, are crappy code... Hangs up windooz (at least it looks like it does for a user..) and say you have a cancel button to cancel the operation, you will never be able to exit that loop.. Heck, you will never be able to end it anyway since a close msg that windooz might send to your program will never be responded to while the loop is running....
-
Mar 21st, 2000, 07:41 PM
#8
Junior Member
Put the DoEvents outside the if statement
just before the 'loop'
Maybe your program loop is not getting to the DoEvents
-
Mar 21st, 2000, 09:48 PM
#9
Also, get rid of the Form. And use a module. Create a Sub routine called Main and change the Startup Object to be Sub Main. This way your application won't have any forms, but will run on a background.
If you meant something else, please, rephrase.
-
Mar 21st, 2000, 10:13 PM
#10
transcendental analytic
no! no! NO! You people don't get it!
Crazy D: "are crappy code... Hangs up windooz "
' I know, I know!!!!! That's why it is complicated.
Crazy D: "You have any special reason for stating that? "
Attemt to Close an app while in loop with doevents will cause program not to close. When you try to restart windows with that, it will wait until a End task window will show up. Thats annoying.
And the solution: When a form (wich have a Unload event that modules don't have) closes, you can end the loop. The code in Kevdogs last reply, will work.
browner: "Put the DoEvents outside the if statement"
That will cause the hangup that Crazy D was talking about
Serge: "Also, get rid of the Form. And use a module. Create a Sub routine called Main and change the Startup Object to be Sub Main. This way your application won't have any forms, but will run on a background."
I just don't want to explain this one more time but the form is really neccesary.
-
Mar 22nd, 2000, 01:37 AM
#11
Thread Starter
Member
Thanks,
Do I need to keep my module? Or can I just put it all in a form?? When I put all my code, in a form before, and turned it invisible it would not execute the code, if I do it this way in a form will it work?
Thanks,
Kevin
-
Mar 22nd, 2000, 01:42 AM
#12
transcendental analytic
Sure thing, Kevdog.
And for that thing i posted "Do NOT use DOEVENTS with continuous loops" I would add: ", if you don't have the unloading procedure"
-
Mar 22nd, 2000, 04:44 AM
#13
Thread Starter
Member
Thanks,
But do I need a module and a form or just a form?? Also, I tried putting all my code in a form, with a the code you gave me and it would not work??
Thanks,
Kevin
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
|