Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » General Visual Basic » pause/wait

25 posts, Page 1 of 3. 123»»»

pause/waitExpand / Collapse
Author
Message
Posted 9/2/2004 9:20:19 PM


Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 9/12/2004 12:29:00 PM
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
Post #3320
Posted 9/2/2004 10:57:48 PM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 3/13/2006 2:34:13 AM
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.






Post #3323
Posted 9/2/2004 11:03:55 PM
Forum God

Forum God

Group: Moderators
Last Login: Today @ 9:00:35 AM
Posts: 1,107, Visits: 10,665

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

Post #3324
Posted 9/3/2004 1:11:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/5/2004 5:14:00 PM
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

Post #3332
Posted 9/3/2004 8:49:48 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 3/6/2013 3:54:06 PM
Posts: 653, Visits: 14

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

Just thought I'd point that out.

James






  

Post #3350
Posted 9/4/2004 8:06:05 AM


Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 5/20/2006 7:21:20 PM
Posts: 189, Visits: 25
wow-2 questions in a row have helped me.(including this 1)

DOS






email me
Post #3416
Posted 6/5/2007 12:03:56 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/5/2007 11:59:29 AM
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

Post #22068
Posted 9/24/2008 8:13:52 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/24/2008 8:16:21 PM
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.

Post #25773
Posted 9/24/2008 8:18:38 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/24/2008 8:16:21 PM
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.

Post #25774
Posted 9/24/2008 9:09:50 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 10/18/2012 11:40:00 AM
Posts: 548, Visits: 2,556
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.

________________________________________________________________ 

"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! 

Post #25775
« Prev Topic | Next Topic »

25 posts, Page 1 of 3. 123»»»

Reading This TopicExpand / Collapse
Active Users: 2 (2 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 12:14pm