Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2004, 09:56 AM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pausing a procedure

I am creating a network analysis tool and the first component I have started working on is a ping utility. I have it working fine but the one thing I want it to do is to ping like the DOS version. I have been looking at the Sleep, Pause, Timer, and Wait methods but can't exactly figure out which one I should be using and how to implement them. I am wanting to pause the code execution between pings for one second. How can I do this. Below is some of the code and the place I think the pause should occur.

For I = 1 To 4
    lstOutput.Items.Add("Reply from " & txtIPAddress.Text & " _
    " :bytes =" & size & " time" & retValue & "ms TTL=" & TTL)
     ' PAUSE EXECUTION HERE FOR ONE SECOND BEFORE EXECUTING
     ' ANOTHER PING.....
     retValue = Packet.Ping
Next I

Could someone show or direct me to a code snippet that would show me how to do this.

Thanks.

Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
__________________
Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
 
Old October 19th, 2004, 10:32 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I feel silly answering your post, because I'm no developer - just an end-user who has done a fair amount of automation in Word and Excel. Anyway, I have had to sprinkle a lot of pauses through my code to allow Excel and Word time to process various commands relating to printing, opening files, activating views, and so on.

Fwiw, here's the procedure I use:

Public Sub DelayBySec(howLong as Integer)
Dim start as Single
start = Timer + howlong
Do While Timer < start
     DoEvents
Loop
End Sub

Cheers

ArtDecade
 
Old October 19th, 2004, 11:12 AM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've used something similar in VBA. Here is what I used:

Dim newHour, newMinute, newSecond, waitTime
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 5 ' the number specifies the amount of time to wait
waitTime = TimeSerial(newHour, newMinute, newSecond)
' PERFORM SOME FUNCTION
Application.Wait waitTime ' pause code

The problem is I haven't been able to successfully convert this to VB.

Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
 
Old October 19th, 2004, 04:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

One line:

System.Threading.Thread.Sleep(5000)

5000 is the number of milliseconds you want it to sleep, in this case 5 seconds. Place this directly in front of the segment you wish to pause.

Note that you should probably also change the cursor to an hourglass prior to this code and change it back afterwards.

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
pausing execution dcher BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 1 January 7th, 2008 04:26 AM
Pausing a rotating image banner 132591 Javascript How-To 1 December 18th, 2006 01:54 AM
Pausing a web application macupryk ASP.NET 1.0 and 1.1 Basics 1 November 5th, 2005 01:51 AM
Pausing Code? edray Beginning VB 6 1 July 9th, 2004 08:02 AM
Running and pausing exe's from DTS Package leehambly SQL Server DTS 2 September 22nd, 2003 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.