cloud Posted August 14, 2003 Posted August 14, 2003 Hi... I'm a newbie in VB.NET... I wanna know is there a way to make the function running pause for a few seconds before re-run itself in a for loop such as below: Function con(ByVal bufferstring As String) As String Dim i As Integer Dim temp As String For i = 0 To bufferstring.Length - 1 temp &= vbCrLf & bufferstring.Chars(i) Next End Function The function above will print characters by characters from the variable "temp". However, it print all in one go. Is there a code to make it print 1 character then wait for 5 seconds before printing the 2nd character and so on... I tried using System.Threading.Thread.Sleep(5000) but it'll just hang there for 5 seconds and then in 1 go, print out all my characters which is not the outcome I want. Anyone got ideas how to do it? Please advice. Thank you..:) Quote
*Experts* mutant Posted August 14, 2003 *Experts* Posted August 14, 2003 Use Application.DoEvents() before every .Sleep() call. :) Quote
cloud Posted August 19, 2003 Author Posted August 19, 2003 Guys.. I got one more question... What if I put the function to sleep already but then I wanna continue that function later.. To make it more simple, I have a for loop function to print numbers from 1 to 10. However, when the loop prints until 5, I want to make the function sleep. Then with a click of a button on the same form, the functions continue to print from 6 to 10 instead of rerunning the whole process. Any ways??? Quote
Mehyar Posted August 19, 2003 Posted August 19, 2003 To match the example you requested declare a private variable to hold the maximum number you reached Private NumReached as Integer = 0 Private Function PrintNumbers(MaxNum as Integer) as String Dim i as integer Dim temp as String = "" 'Loop from where you reached to MaxNum For i = NumReached to MaxNum Temp = Temp & i & " " Next 'Set the NumReached to the new value reached NumReached = MaxNum Return Temp End Function Each time you click the button pass the MaxNum as you want Hope this is clear... Quote Dream as if you'll live forever, live as if you'll die today
cloud Posted August 20, 2003 Author Posted August 20, 2003 Manage to work out the coding already. Thanks for the help.. Quote
wyrd Posted August 20, 2003 Posted August 20, 2003 Could you post your findings, that way those who do a search in the future can have their same question answered. :) To the subject at hand.. I believe you can do Thread.Suspend() which stops the thread, then do Thread.Resume() to continue execution. Quote Gamer extraordinaire. Programmer wannabe.
cloud Posted August 21, 2003 Author Posted August 21, 2003 Yeap, wyrd.. the thread thing solves the problem.. Anyway, how do I post my findings? I'm newbie..Still trying to figure out my way in here..:) Quote
wyrd Posted August 21, 2003 Posted August 21, 2003 Just explain briefly how you solved the problem and provide a small code snippet (if possible). If what I explained was what you did then don't worry about it. :) You don't have to if you don't want to, it's just a courtesy to whoever may have the same problem in the future (as a search on the forums would provide an answer rather then them having to make a post and wait for a reply) Quote Gamer extraordinaire. Programmer wannabe.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.