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 » Visual Basic (VB 4/5/6) » General Visual Basic » pause/wait

18 posts, Page 2 of 2. ««12

pause/waitExpand / Collapse
Author
Message
Posted 9/24/2008 11:10:51 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 10:12:38 PM
Posts: 349, Visits: 1,708
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.

 

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

***Vote here to make Keith a Moderator***

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

Post #25776
Posted 9/24/2008 11:16:22 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 10:12:38 PM
Posts: 349, Visits: 1,708
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.

 

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

***Vote here to make Keith a Moderator***

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

Post #25777
Posted 9/25/2008 12:35:37 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 10:12:38 PM
Posts: 349, Visits: 1,708
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!

'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'


 

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

***Vote here to make Keith a Moderator***

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

Post #25779
Posted 9/25/2008 1:27:13 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/25/2008 1:17:47 AM
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
Post #25780
Posted 9/25/2008 8:56:11 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 10:12:38 PM
Posts: 349, Visits: 1,708
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"!

***Vote here to make Keith a Moderator***

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

Post #25781
Posted 9/25/2008 6:06:04 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 7:34:31 PM
Posts: 1,465, Visits: 3,404
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.

I thought you would have known that Chris?

Keith

http://www.martin2k.co.uk/forums/

I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #25787
Posted 9/25/2008 10:44:20 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 10:12:38 PM
Posts: 349, Visits: 1,708
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.

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?

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

***Vote here to make Keith a Moderator***

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

Post #25792
Posted 9/26/2008 7:12:55 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 7:34:31 PM
Posts: 1,465, Visits: 3,404
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?

I've read it now.

Keith

http://www.martin2k.co.uk/forums/

I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #25794
« Prev Topic | Next Topic »

18 posts, Page 2 of 2. ««12

Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Brian, Peter

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 3:41am