Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait for called Subroutine to finish

Status
Not open for further replies.

jonnyknowsbest

Technical User
Feb 3, 2004
163
GB
I have a subroutine called "Spell Check" that is called when a user clicks on a button.

However, i want processing of the buttons _Click event to be suspended until the spell check sub has finished. How do i do this?
 
You can do this
Code:
Public Sub SpellCheck()
 'as soon as the sub is entered, disable the button  
 [your button].Disabled = true
 [your spell check code]
 'before i exit the sub, enable the button 
 [your button].Disabled = false
End Sub
 
NOt sure i explained myself very well. THe code runs like this:

========================================
Private Sub Button_Click

Spell_Check()

Code to save file goes here

MsgBox "File has been saved", vbOKOnly

End Sub
=======================================

I want the "Code to save file" and Msgbox not to happen until the Spell_Check() sub has finished.
 
In order for your 'Code to save file goes here" and your final MsgBox to pop up after everything else is doen, put your save file code in a seperate subroutine (or function if you want it to return a sucess code). When you run the application your Spell_Check routine will run, control will then return to the button_click event, the next routine (save your file) will execute. Again control will return to the click event and your message box will display.
 
Take a look at what Rick wrote in faq796-5929 and faq796-6036 and faq796-6056.

I believe that it will solve your problem.
 
if Spell_Check running asychronously? If so, you will need to track it's thread state and hold the primary thread until it's done.

Then why do you want to put it in another thread??

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
My guess is that the Spell_Check method runs in another thread. Which means you're going to need some kind of state tracking on it to know when it gets done. Wether it's a callback method, a property that exposes thread.threadstate, or a custom event and handler, some how you need to find out when the spell check finishes.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top