|
-
Sep 14th, 2000, 04:46 PM
#1
Thread Starter
Junior Member
I am running a VB program to open and close various MS Word documents..
The program can take up to five minutes to complete..
How can I leave a command button (or whatever) active on the screen to enable to me stop/break the program without having to wait for the program to complete?
Thanks,
Graham.
-
Sep 14th, 2000, 04:57 PM
#2
Try adding a DoEvents which I think will let you do other stuff while the program is processing.
-
Sep 14th, 2000, 05:04 PM
#3
Thread Starter
Junior Member
Thanks but...
I actually want to stop the program.
Graham.
-
Sep 14th, 2000, 06:17 PM
#4
Stop it..as in exiting the application? Or the individual MS Word documents?
-
Sep 14th, 2000, 06:25 PM
#5
Hyperactive Member
Who is in control?
IS your application in control for this 5 minute period? OR has your program called some method on the Word Document that means you are just waiting for VB to get control again?
If you are in control, then Matthew's suggestion means to add a DoEvents call in your main loop - someplace where it will get attention quite frequently.
This means that any button you have on your form will have a chance at being pressed whereas normally, VB will only bother to see if the button is pressed when it has finished the current task.
Hope it helps
-
Sep 14th, 2000, 06:34 PM
#6
Thread Starter
Junior Member
Stop it - as in exiting the application.
I am selecting a sub-directory on a file server and performing functions on all Word docs found.
Sometimes I accidentally select the wrong directory and I want to stop before it goes too far and does damage to the wrong set of sub directories i.e. Kill the application in mid program (up until now I have to use ctrl-alt-del).
Graham.
-
Sep 14th, 2000, 06:47 PM
#7
Are you selecting them through your program?
Because just have a confirm message come up and ask if that's the file you want to use.
Code:
confirm = Msgbox("Are you sure you want that file?", 4 + 32)
If confirm = vbYes Then
'do your code
Else
End If
-
Sep 14th, 2000, 07:05 PM
#8
If your code is looping, have a look at this old loop to stop the loop.
-
Sep 14th, 2000, 07:12 PM
#9
Thread Starter
Junior Member
Thanks for the help guys - but I'm still not getting it.
The program is running - I just want to kill it by clicking a button or pressing a key.
My program is looping - so I could put some code in to look for a particular key press..
How would I look for a keypress while the program is looping?
Graham.
-
Sep 14th, 2000, 07:34 PM
#10
Hyperactive Member
Better explanation for you
Since you said you're not getting it, here are the "rules" you ought to follow for now:
1) have your VB form visible while the word processing is happening. If that is not possible, tell us why.
2) Make an ABORT button on your app that does the following:
2.1) Closes any open word docuemnts and then removes the word object from memory (i.e. set oWord = Nothing). Otherwise you end up with Word tasks kicking around.
2.2) tidies up any other objects or files you had in use during the main loop.
3) In your main loop add a statement DoEvents.
If you do this, you will be able to make your application abort upon clicking the button.
Let us know if you get stuck on any of these steps.
Regards
-
Sep 14th, 2000, 07:42 PM
#11
Thread Starter
Junior Member
Thanks for the help Paul,
I'll follow that route.
Graham.
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
|