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


pause/wait


pause/wait

Author
Message
CDRIVE
CDRIVE
Forum God
Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Dalahastine (9/3/2004)
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."
End Sub

You told the TS to put a Timer on his Form....What for?? There's no Timer involved in your code. Nor does it need it. Whistling

________________________________________________________________ 

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

Edited
9/24/2008 by CDRIVE
CDRIVE
CDRIVE
Forum God
Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
skizznott (6/5/2007)

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

You should not be posting NET code here. It will just confuse the issue.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! 

CDRIVE
CDRIVE
Forum God
Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Be aware that all the code posted in this thread has a downside. Even the Sleep API posted by Mark, who I have the utmost respect for. The Sleep API is fine if you don't want anything else in your app to be processed during the Sleep period. During the Sleep period your entire app... code....CommandButtons ...Timers ..everything is in a comatose state. Set Sleep for Sleep 10000 and try to click a CommandButton.

The rest of the examples won't have that problem but will suck up processor cycles like a Black Hole. Open up your Task Manager and go to the Performance tab (XP) or System Tools (Resource Meter) in W98. Then run anyone of the other postings with the Pause or Delay  period of 10 seconds and watch the resource meter.

This code is the best of both worlds, as it combines the Sleep API with a Pause Sub. Since the Sleep value is held constant @ 1mS * 2 (called twice) it won't freeze your app, even with a very long Pause value. This code won't suck your processor dry either! Smile Wink

'http://www.martin2k.co.uk/forums/index.php?s=b53bcad9aa27dd0bd8f62236ce4f9548&showtopic=4767&st=0&#entry66501
'beatle ' date='Jul 18 2008, 12:24 PM' post='66518'] The "By Wayne" comment would
'suggest so. Your not handling the possibility of an over midnight pause, which
'although rare would put it in an infinite loop. You could also use Sleep API to
'save hammering the cpu.
'Notes: This modified Pause Sub by Beatle doesn't eat CPU cycles!!!!


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

' Credits: (Beatle aka Milk (Sleep+Pause Sub)). (Wayne Spangler (Pause Sub))
Private Sub Pause(ByVal Delay As Single)
   Delay = Timer + Delay
   If Delay > 86400 Then 'more than number of seconds in a day
      Delay = Delay - 86400
      Do
          DoEvents ' to process events.
          Sleep 1 ' to not eat cpu
      Loop Until Timer < 1
   End If
   Do
       DoEvents ' to process events.
       Sleep 1 ' to not eat cpu
   Loop While Delay > Timer
End Sub

Private Sub Form_Load()
   Form1.Show
   Pause 10
   Form1.Caption = "Pause has timed out!"
End Sub

 

Sexy code formating by Mark's 'SyntaxHighlighter' Cool


________________________________________________________________ 

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

Edited
9/24/2008 by CDRIVE
anni
anni
Forum God
Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)Forum God (379 reputation)

Group: Forum Members
Posts: 1, Visits: 1
It's not possible to see your previous post while giving reply.I think it's not necessary also.Why you are asking for that.Is there any such type of requirement?

_______________________________________________________________

Anni

best webhosting companies

web hosting
CDRIVE
CDRIVE
Forum God
Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
anni (9/25/2008)
It's not possible to see your previous post while giving reply.I think it's not necessary also.Why you are asking for that.Is there any such type of requirement?

Welcome to A1.

What do you mean by "not possible"? Most forums display all the previous posts in the thread so you can efference any given post while replying or quoting.

________________________________________________________________ 

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

Keithuk
Keithuk
Forum God
Forum God (297K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
Welcome to A1vbcode Anni

anni (9/25/2008)
It's not possible to see your previous post while giving reply.

Yes I'm afraid thats a little glitch of this forum. You can't see previous posts when you reply, the only other way around it is have 2 browsers open and copy and paste. Wink

I thought you would have known that Chris?

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

CDRIVE
CDRIVE
Forum God
Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)Forum God (102K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Keithuk (9/25/2008)
Welcome to A1vbcode Anni

anni (9/25/2008)
It's not possible to see your previous post while giving reply.

Yes I'm afraid thats a little glitch of this forum. You can't see previous posts when you reply, the only other way around it is have 2 browsers open and copy and paste. Wink

I thought you would have known that Chris?

I did know that.  Before IE7 I would either open a duplicate page in a new window or start another instance of IE. Did you read this? Wink

http://www.a1vbcode.com/vbforums/FindPost25775.aspx

________________________________________________________________ 

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

Keithuk
Keithuk
Forum God
Forum God (297K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
CDRIVE (9/25/2008)

I did know that.  Before IE7 I would either open a duplicate page in a new window or start another instance of IE. Did you read this? Wink

I've read it now. Wink

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Cirdan
Cirdan
Forum God
Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)Forum God (700 reputation)

Group: Forum Members
Posts: 2, Visits: 4
Hey Guys,



Thanks for the suggestions in this thread; I've been coding in VBA for years and am making the transition to VB.Net for an Attachment Processor I'm writing for Outlook. In doing so, I realized that the NewMailEx event doesn't fire on messages delivered to your mailbox while you had Outlook closed, and not all of our users run in Cached Mode.



Here's the code I used for my own delay by making use of the Timer object for 5 seconds. This allows Outlook to do what it needs to do during the delay period, then just stops and disables the timer after the first run. This works in Visual Studio 2008 and Outlook 2007. I've yet to test it on OL2k3 or OL2k.





Public Class ThisAddIn

Public timber As New Timer

'Don't use a WithEvents call here, or you won't be able to stop it.



Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

timber.Interval = 5000

AddHandler timber.Tick, AddressOf timber_Initialize

timber.Enabled = True

End Sub



Private Sub timber_Initialize()

MsgBox("Because new messages may have been delivered while Outlook was closed, I must now" & vbCrLf _

& "check the most recent items delivered to ensure they are processed." & vbCrLf _

& "Thank you for your patience.")

timber.Stop()

timber.Enabled = False

InitialProcess() ' Which runs the Attachment Processor for recently-received MailItems.

End Sub



Private Sub InitialProcess()

' < your main code here >

End Sub





Considering how much reading forums like this one has helped me, I wanted to contribute by posting what I ended up using. Of course, feedback is appreciated!



Take care, everyone!

Cir



EDIT: Not sure why the [code] block doesn't work...

"Don't follow in my footsteps; I walk into walls."
Edited
11/11/2009 by Cirdan
Keithuk
Keithuk
Forum God
Forum God (297K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
Welcome to A1vbcode Cirdan.

I wouldn't confuse this old topic any more. We do have a VBA(Excel, Word etc) or the Visual Basic .NET/2005/2008 forum. 

Cirdan (11/11/2009)
Hey Guys,

EDIT: Not sure why the [code] block doesn't work...

The [Code] [/Code ] functions don't work correctly on this forum. As Chris has suggested we have Mark's Syntax.zip to make the VB code show correctly. Wink

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search