Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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..:)

Posted

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???

Posted

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...

Dream as if you'll live forever, live as if you'll die today
Posted

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.

Gamer extraordinaire. Programmer wannabe.
Posted

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..:)

Posted

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)

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...