Can you pause a loop?

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 9870 Views - Last Post: 15 April 2013 - 01:27 PM Rate Topic: -----

#1 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Can you pause a loop?

Posted 17 May 2009 - 02:56 AM

Is there a way to pause a for - each loop? if so how. and by pause I mean stop the loop for a XX amount of time.
Is This A Good Question/Topic? 0
  • +

Replies To: Can you pause a loop?

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:06 AM

try to use
Exit Loop


Was This Post Helpful? 0
  • +
  • -

#3 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:11 AM

View Postnoorahmad, on 17 May, 2009 - 02:06 AM, said:

try to use
Exit Loop




		Dim myChar As Char

		For Each myChar In TextBox2.Text
			RichTextBox2.Text = RichTextBox2.Text + myChar.ToString

		Next



thing is if I exit then I cant complete the operation.
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:20 AM

when you want to stop the loop
for each myChar in TextBox2.Text
RichTextBox2.Text = RichTextBox2.Text + myChar.ToString
	If myChar = "something" Then
					Exit For
				End If
next


Was This Post Helpful? 0
  • +
  • -

#5 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:36 AM

View Postnoorahmad, on 17 May, 2009 - 02:20 AM, said:

when you want to stop the loop
for each myChar in TextBox2.Text
RichTextBox2.Text = RichTextBox2.Text + myChar.ToString
	If myChar = "something" Then
					Exit For
				End If
next



thing is I dont want to stop it just pause it
Was This Post Helpful? 0
  • +
  • -

#6 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Can you pause a loop?

Posted 17 May 2009 - 03:42 AM

You could use this:

  Dim myChar As Char
		For Each myChar In TextBox2.Text
			RichTextBox2.Text = RichTextBox2.Text + myChar.ToString
			System.threading.thread.sleep(1000)
		Next




That will wait for 1 second (1000ms) between each operation
Was This Post Helpful? 0
  • +
  • -

#7 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:43 AM

View PostJack Eagles1, on 17 May, 2009 - 02:42 AM, said:

You could use this:

  Dim myChar As Char
		For Each myChar In TextBox2.Text
			RichTextBox2.Text = RichTextBox2.Text + myChar.ToString
			System.threading.thread.sleep(1000)
		Next




That will wait for 1 second (1000ms) between each operation


wont this make the program not respond though between seconds? but thanks
Was This Post Helpful? 0
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:46 AM

try this:
System.Threading.Thread.Sleep(3000) 'time in Milliseconds


Was This Post Helpful? 0
  • +
  • -

#9 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 03:49 AM

this does not work it just makes my program not respond
Was This Post Helpful? 0
  • +
  • -

#10 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Can you pause a loop?

Posted 17 May 2009 - 04:05 AM

you can use BackGroundWorker
search it, you will find it in tutorial section
Was This Post Helpful? 0
  • +
  • -

#11 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 04:36 AM

View Postnoorahmad, on 17 May, 2009 - 03:05 AM, said:

you can use BackGroundWorker
search it, you will find it in tutorial section


i tried but I cant change this section of code

 ' The delegate
 Delegate Sub SetLabelText_Delegate(ByVal [Label] As Label, ByVal [text] As String)

' The delegates subroutine.
 Private Sub SetLabelText_ThreadSafe(ByVal [Label] As Label, ByVal [text] As String)
  ' InvokeRequired required compares the thread ID of the calling thread to the thread ID of the creating thread.
  ' If these threads are different, it returns true.
  If [Label].InvokeRequired Then
   Dim MyDelegate As New SetLabelText_Delegate(AddressOf SetLabelText_ThreadSafe)
   Me.Invoke(MyDelegate, New Object() {[Label], [text]})
  Else
   [Label].Text = [text]
  End If
 End Sub



to get it to work with my code can you explain how to change it for me please
Was This Post Helpful? 0
  • +
  • -

#12 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Can you pause a loop?

Posted 17 May 2009 - 04:40 AM

explain your work i will tell what to do, i mean what do you want to do and pause your loop

This post has been edited by noorahmad: 17 May 2009 - 04:40 AM

Was This Post Helpful? 0
  • +
  • -

#13 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 04:43 AM

View Postnoorahmad, on 17 May, 2009 - 03:40 AM, said:

explain you work i will tell what to do, i mean what do you want to do and pause you loop



baisicly I am creating a typewritter effect which is okay with a timer and this code -
  If y = 0 Then
			y = y + 1
			Label1.Text = "H"
		ElseIf y = 1 Then
			y = y + 1
			Label1.Text = Label1.Text + "E"
		ElseIf y = 2 Then
			y = y + 1
			Label1.Text = Label1.Text + "L"
		ElseIf y = 3 Then
			y = y + 1
			Label1.Text = Label1.Text + "L"
		ElseIf y = 4 Then
			y = y + 1
			Label1.Text = Label1.Text + "O"
		ElseIf y = 5 Then
			Button1.Text = "Start"
			Timer1.Enabled = False
			z = False
			y = 0
			MsgBox("cycle complete")
		End If



but I would quite like to do it more dynamicly so I have this method

		Dim myChar As Char

		For Each myChar In TextBox2.Text
			RichTextBox2.Text = RichTextBox2.Text + myChar.ToString

		Next



but I need to find a way to pause between entering the characters and when you sleep the thread it just doesnt work right so multi threadding may be better. the code I think would have to be used in the background worker.
Was This Post Helpful? 0
  • +
  • -

#14 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Can you pause a loop?

Posted 17 May 2009 - 04:51 AM

you want to show text in textbox in slow motion
if i am rite then you can use Timer i used it for slow text motion in textbox
Was This Post Helpful? 0
  • +
  • -

#15 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Can you pause a loop?

Posted 17 May 2009 - 04:54 AM

View Postnoorahmad, on 17 May, 2009 - 03:51 AM, said:

you want to show text in textbox in slow motion
if i am rite then you can use Timer i used it for slow text motion in textbox



yes thank you do you know or rember how?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2