| | |
Using Delay or Pause, without the whole thing freezing?
![]() |
•
•
Join Date: May 2003
Posts: 36
Reputation:
Solved Threads: 0
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:
And if I were to click it, it would pause for a while, maybe freeze, then display "Cat".
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)
Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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:15 am.
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.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
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.
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.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
•
•
Join Date: Aug 2006
Posts: 2
Reputation:
Solved Threads: 0
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 >>>
Job Done ? :cheesy:
So the quick and simple solution would be >>>
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
txtWords.Text = "Hello" Sleep 300 txtWords.Text = "Cookie" txtWords.refresh Sleep 300 txtWords.Text = "Train" txtWords.refresh Sleep 300 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.
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):
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)
for each XFrm in Forms unload XFrm next XFrm ' /* Code Should Never Reach Here, But Just In Case */ End
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
TxtWords.Text = "Hello" DoEvents Sleep 300 TxtWords.Text = "Cookie" DoEvents Sleep 300 TxtWords.Text = "Train" DoEvents Sleep 300 TxtWords.Text = "Cat"
•
•
Join Date: Feb 2007
Posts: 28
Reputation:
Solved Threads: 3
I agree with Comatose - this is a much better way.
•
•
Join Date: Feb 2007
Posts: 114
Reputation:
Solved Threads: 8
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
See here for a fuller explanation
http://www.devx.com/vb2themax/Tip/18646
Regards
D
![]() |
Similar Threads
- Long Pause During Windows Statup Process (Windows NT / 2000 / XP)
- Freezing For No Reason!! (Troubleshooting Dead Machines)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Extract MS Excel Data embedded in MS Word
- Next Thread: creating a database in vb
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






