Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


pause/wait


pause/wait

Author
Message
T1nM4n
T1nM4n
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 42, Visits: 1
is there any sort of cammnd to make a program wait a given time, like pause 5 to pause 5 seconds or like wait, or sumthing, i just need the program to "wait"

thnx
t1n
pso
pso
Forum God
Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)Forum God (73K reputation)

Group: Forum Members
Posts: 794, Visits: 338
hi T1N,
'Delay 5 seconds
' use :
' show a splash screen or process something here
Call Delay(5)
' Unload your Splash screen here, or pick up where processing something has finished -and you know it won't take more than delay time passed as arg.

Sub Delay(dblSecs As Double)
Const OneSec As Double = 1# / (1440# * 60#)
Dim dblWaitTil As Date

dblWaitTil = Now + OneSec * dblSecs
Do Until Now > dblWaitTil
DoEvents ' Allow windows messages to be processed
Loop

End Sub

I have tested this sub (from EE) site and have used many times.






Tongue

Mark
Mark
Forum God
Forum God (141K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

Often times there is more than one way to do things. Here is an API solution.

 

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
    MsgBox "The back color of the form will change 5 seconds after you close this message box."
    Sleep 5000
    Me.BackColor = vbBlue
End Sub


Dalahastine
Dalahastine
Forum God
Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)Forum God (421 reputation)

Group: Forum Members
Posts: 5, Visits: 1

Here is a very simple method I've used quite a bit.

add a timer to your Form and set it's duration to 60000, then add this Sub.


Public Sub Pause(duration As Long)
       Dim Current As Long
    Current = Timer
    Do Until Timer - Current >= duration
        DoEvents
    Loop
End Sub


 

Now, whenever you want something to Pause for a certain amount of time just write.

 

Pause whatever

** Example **


Private Sub Command1_Click()
MsgBox "This will Pause for 3 seconds.", vbExclamation, "3 Second Pause."
Pause 3
MsgBox "This will Pause for 2 seconds.", vbExclamation, "2 Second Pause."
Pause 2
MsgBox "This will Pause for 1 seconds.", vbExclamation, "1 Second Pause."
Pause 1
MsgBox "Pause Demo Complete.", vbExclamation, "Pause Demo Complete."
End Sub

 


 

It's really easy.

Good Luck


James
James
Forum God
Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)Forum God (116K reputation)

Group: Forum Members
Posts: 653, Visits: 14

Set the interval to 1000 not 60000. 1000 = 1sec 60000 = 1min.

Just thought I'd point that out.

James






  


DOS
DOS
Forum God
Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)Forum God (29K reputation)

Group: Forum Members
Posts: 189, Visits: 25
wow-2 questions in a row have helped me.(including this 1)

DOS






email me
skizznott
skizznott
Forum God
Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)Forum God (411 reputation)

Group: Forum Members
Posts: 1, Visits: 1

I think that God's initial post is the best way but here is a revised version that will work with .NET 2005 (Newer versions of .NET do not like Now + OneSec, you must use the Now.AddSeconds(OneSec).  Also you need to instantiate DoEvents you can't just call it any longer.  Use Application.DoEvents()

Sub Delay(ByVal dblSecs As Double)

Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
Dim dblWaitTil As Date
Now.AddSeconds(OneSec)
dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
Do Until Now > dblWaitTil
Application.DoEvents()
' Allow windows messages to be processed
Loop

End Sub


DavidKennedy
DavidKennedy
Forum God
Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)

Group: Forum Members
Posts: 2, Visits: 2
Sub Delay(), written by Newbie, works for me, but it has brought back that dreaded, "beep", that I have only just learned to suppress in my Text1.KeyDown Subroutine using,

eventArgs.SuppressKeyPress = True

is the beep inevitable?

My application performs a calculation when the user presses the "Enter" key.  However, the calculation and posted anwer is performed so quickly, the user might not be sure it has been done correctly.  So I want to change the font colour in the answer box to another colour for about 1/10th of a second, to give the impression of a quich flash, indicating to the user that the calculation has been done.


DavidKennedy
DavidKennedy
Forum God
Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)Forum God (754 reputation)

Group: Forum Members
Posts: 2, Visits: 2
Sorry, my first time.  That "Newbie" would be "skizznott".

Its a pity that one can't view the previous postings when writing a reply.

CDRIVE
CDRIVE
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
DavidKennedy (9/24/2008)
Sorry, my first time.  That "Newbie" would be "skizznott".

Its a pity that one can't view the previous postings when writing a reply.

Yes, unlike other VB forums A1 won't let you scroll through all the other posts in the thread while Quoting or Replying. When clicking 'Quote Posted Reply' it will insert the text of that single post within your reply. To see all of the posts I usually open another IE tab as a work around. Wink

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search