Using Delay or Pause, without the whole thing freezing?

Reply

Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Using Delay or Pause, without the whole thing freezing?

 
0
  #1
Jul 4th, 2003
I'm still using VB6 unfortunetly, but anyway, how would I go about implementing this?
Say I wanted to do something so when you click a button the text in a textbox changes but has a 200-300 millisecond delay so it looks as if the words are changing really fast. But whenever I try to do it, I click the button to test it, and it waits like 4 seconds(freezes), then displays the last word I put for it to display. How do I fix that?

Here's an example:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdProduceWords_Click()
  2. txtWords.Text = "Hello"
  3. Sleep 300
  4. txtWords.Text = "Cookie"
  5. Sleep 300
  6. txtWords.Text = "Train"
  7. Sleep 300
  8. txtWords.Text = "Cat"

And if I were to click it, it would pause for a while, maybe freeze, then display "Cat".
Last edited by Comatose; Aug 14th, 2006 at 9:15 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 27
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Using Delay or Pause, without the whole thing freezing?

 
0
  #2
Jul 4th, 2003
Why not put the code into a timer?
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 27
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Using Delay or Pause, without the whole thing freezing?

 
0
  #3
Jul 4th, 2003
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q231/2/98.asp&NoWebContent=1

There is the answer to your problem. God bless Microsoft Knowledge Base.
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2
Reputation: Paul finch is an unknown quantity at this point 
Solved Threads: 0
Paul finch Paul finch is offline Offline
Newbie Poster

Re: Using Delay or Pause, without the whole thing freezing?

 
0
  #4
Aug 1st, 2006
Your freezing really isnt the issue, you code seems fine. The problem is that the app doesnt have enough time to refresh the text boxes.

So the quick and simple solution would be >>>

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. txtWords.Text = "Hello"
  2. Sleep 300
  3. txtWords.Text = "Cookie"
  4. txtWords.refresh
  5. Sleep 300
  6. txtWords.Text = "Train"
  7. txtWords.refresh
  8. Sleep 300
  9. txtWords.Text = "Cat"

Job Done ? :cheesy:



Originally Posted by Mr Gates
I'm still using VB6 unfortunetly, but anyway, how would I go about implementing this?
Say I wanted to do something so when you click a button the text in a textbox changes but has a 200-300 millisecond delay so it looks as if the words are changing really fast. But whenever I try to do it, I click the button to test it, and it waits like 4 seconds(freezes), then displays the last word I put for it to display. How do I fix that?

Here's an example:

-------
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
-------
Private Sub cmdProduceWords_Click()
txtWords.Text = "Hello"
Sleep 300
txtWords.Text = "Cookie"
Sleep 300
txtWords.Text = "Train"
Sleep 300
txtWords.Text = "Cat"
-------


And if I were to click it, it would pause for a while, maybe freeze, then display "Cat".
Last edited by Comatose; Aug 14th, 2006 at 9:16 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Using Delay or Pause, without the whole thing freezing?

 
0
  #5
Aug 14th, 2006
Right, Paul had the right answer. You'll also find (which may be a better solution, since the .refresh method doesn't give windows a chance to update anything other than the textbox) that the doevents function will also work. Doevents, unlike .refresh, gives your app a chance to process events passed by the user. An example of this, is to stick another button on that form, for "quit", and have it have some unload and end code (like so):
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. for each XFrm in Forms
  2. unload XFrm
  3. next XFrm
  4.  
  5. ' /* Code Should Never Reach Here, But Just In Case */
  6. End
Then, click your button to make the words change, and right after, click the Quit button. With the .refresh method, you'll see that it takes a lag time before ending the application. If you use the Doevents function, your application will respond more promptly to device control. The example I have here isn't as extreme as it could be (say, by having another textbox in which you type in at the same time), but it's enough to show you the difference between .refresh and doevents.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. TxtWords.Text = "Hello"
  2. DoEvents
  3. Sleep 300
  4. TxtWords.Text = "Cookie"
  5. DoEvents
  6. Sleep 300
  7. TxtWords.Text = "Train"
  8. DoEvents
  9. Sleep 300
  10. TxtWords.Text = "Cat"
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 28
Reputation: mjwest10 is an unknown quantity at this point 
Solved Threads: 3
mjwest10 mjwest10 is offline Offline
Light Poster

Re: Using Delay or Pause, without the whole thing freezing?

 
0
  #6
Mar 27th, 2007
I agree with Comatose - this is a much better way.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Using Delay or Pause, without the whole thing freezing?

 
0
  #7
Mar 28th, 2007
Actually I would disagree with this, refresh is the appropriate command to use here. DoEvents is for allowing further user interaction whilst code is executing, not for refreshing controls on a form.

See here for a fuller explanation
http://www.devx.com/vb2themax/Tip/18646


Regards

D
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC