Procedure Question

  • Thread starter Thread starter Roshawn
  • Start date Start date
R

Roshawn

Hi,

I have a procedure that runs a For ... Next loop. See below.

Private Sub DoThis()
Dim i As Integer
For i = 1 to 10
'code omitted because I don't want you to see it :-)
Next i
End Sub

What I would like to do is create a one second time frame between each time
the For...Next loop runs. Any suggestions on how to accomplish this?

Thanks,
Roshawn
 
Hi,

I have a procedure that runs a For ... Next loop. See below.

Private Sub DoThis()
Dim i As Integer
For i = 1 to 10
'code omitted because I don't want you to see it :-)
Next i
End Sub

What I would like to do is create a one second time frame between each time
the For...Next loop runs. Any suggestions on how to accomplish this?

Thanks,
Roshawn

Put the code in a timer event, with the interval set to 1000

Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
Static i As Integer = 0

i += 1
If i < 10 Then
' Do Stuff
Else
' Where all done..
Timer.Enabled = False
i = 0
End If
End Sub

or alternatively, you can put it on another thread and then call
Thread.Sleep(1000) between iterations...
 
Private Sub DoThis()
Dim i As Integer
For i = 1 to 10
'code omitted because I don't want you to see it :-)
System.Threading.Thread.Sleep(1000) 'sleep time in milliseconds;
so this sleeps for 1 sec
Next i
End Sub

that should work..

Imran.
 
Back
Top