Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do While loop 3 times

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
GB
Hi,

I have a simple do while loop which calls a function to check ping status. Is there a way I can loop it say 5 times then quit? I need to wait for 1 minute then assume computer not coming back!


do while reachable(IPAddress) = false
wscript.sleep 10000
If Reachable(IPAddress) Then
wscript.echo "Ping back"
Else
WScript.Echo "Computer is Unreachable!"
End If
loop

I have been looking at the for i = 1 to 5 but tis isnt workign...

Thanks
 

hi,
Code:
dim i as integer

do while reachable(IPAddress) = false
wscript.sleep 10000
If Reachable(IPAddress) Then
wscript.echo "Ping back"
Else 
WScript.Echo "Computer is Unreachable!"
End If
i=i+1
if i=5 then exit do
loop

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi,

Yes that seems to work. Is there a way to echo to the screen if perhaps i=5 and reachable is still false?

do while reachable(IPAddress) = false

wscript.sleep 10000
If Reachable(IPAddress) Then
wscript.echo "Ping back"
Else
WScript.Echo "Computer is Unreachable!"
End If
i=i+1
if i=5 then exit do
loop

Maybe something like
if i=5 & reachable = false wscript.echo "Ooops, something went wrong
 
Change
Code:
if i=5 then exit do
to:
Code:
if i = 5 and Not reachable then
  wscript.echo("Oops, something went wrong!")
  exit do
end if

Also, the i=i+1 statement should be the last thing before the "loop" statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top