473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

My.Computer.network.ping Do Until Loop

17
Hi People,

Im trying to do a simple Loop where by an IP address is pinged (Using My.computer.network.ping) and the results, true or false, are used to invoke another line of code.
Basically if the IP is pingable (true) image A is displayed if it is not (false) then image B is.

The code i am using is as follows

Expand|Select|Wrap|Line Numbers
  1. Dim IPAddress As String = "192.168.1.122"
  2.  
  3.         If My.Computer.Network.Ping(IPAddress) = False Then
  4.  
  5.             Do Until True
  6.             Loop
  7.  
  8.             PictureBox1.Visible = True
  9.         Else
  10.             PictureBox2.Visible = True
  11.  
  12.         End If
  13.  
  14. End Sub
  15.  
The code compiles fine however it doesnt seem to loop the ping command. For example unplugging the network cable from the target machine and plugging it back in doesnt result in the app showing image A then B (A= Connected B= Disconnected). I thought that by looping the Network.ping, it will continuously do so until the arguement is reached (true)

Im new to VB.NET environment so any suggestions or advice you can give would be great.

Thanks in advance

Sy
Feb 23 '08 #1
3 11844
jagged
23
Hi People,

Im trying to do a simple Loop where by an IP address is pinged (Using My.computer.network.ping) and the results, true or false, are used to invoke another line of code.
Basically if the IP is pingable (true) image A is displayed if it is not (false) then image B is.

The code i am using is as follows

Expand|Select|Wrap|Line Numbers
  1. Dim IPAddress As String = "192.168.1.122"
  2.  
  3.         If My.Computer.Network.Ping(IPAddress) = False Then
  4.  
  5.             Do Until True
  6.             Loop
  7.  
  8.             PictureBox1.Visible = True
  9.         Else
  10.             PictureBox2.Visible = True
  11.  
  12.         End If
  13.  
  14. End Sub
  15.  
The code compiles fine however it doesnt seem to loop the ping command. For example unplugging the network cable from the target machine and plugging it back in doesnt result in the app showing image A then B (A= Connected B= Disconnected). I thought that by looping the Network.ping, it will continuously do so until the arguement is reached (true)

Im new to VB.NET environment so any suggestions or advice you can give would be great.

Thanks in advance

Sy
Do until True
Loop

essentially does nothing. You loop until the condition after "until" specified is true. Since you set it to true, it never enters the loop.

You want something like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Do 
  3.         If My.Computer.Network.Ping(IPAddress) = False Then
  4.             PictureBox1.Visible = True
  5.         Else
  6.             PictureBox2.Visible = True 
  7.         End If
  8.         Application.DoEvents();
  9.         // System.Threading.Thread.Sleep(1000);
  10.  
  11.  Loop
  12.  
I'm not too familiar with vb.net (expert with "old" VB) so maybe the syntax changed, but your loop needs to be outside the IF .... ping ... Then block.

Bear in mind that this will continously ping the server (hundreds of times in a second I would assume) so you may want to use a timer (if you have a form) or System.Threading.Thread.Sleep(1000)
Feb 23 '08 #2
SyGC
17
Hi Jagged

yes indeed in my infinite newbiness i should of put the IF statement inside the DO until Loop.

However something strange now happans. After implementing your code and compiling my Form no longer appears. Debugging is occuring but i dont see my form.

If i quote out the 'Do' and 'Loop' and compile my form again i can see it.

Any Ideas?

Thanks again
Sy
Feb 23 '08 #3
jagged
23
Where is this code? Is it in the form_load event?

Did you include the Application.DoEvents()? That processes other messages on the queue, like drawing the form so if you left it out, that could be why you don't see the form.

What you should do is drag a timer on your form, double click on it to open the event handler and then paste the IF Then block in there (no do .. loop). Set the interval to 1000 (1 second) and make sure enabled = true. This way, the ping will occur every second and it's not blocking the rest of your app from working.
Feb 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Eric | last post by:
Let me start off by saying I have VB working model which means no help. I have searched MSDN. It seems that I get "Read the help" instead of answers which is totally useless to me. With that...
1
by: Sam the Cat | last post by:
Besides calling the external ping utility -- is there a way native to python to execute a similar utility ?
4
by: .Net Sports | last post by:
I am trying to display records from a recordset after sql statement: <% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '" & request.querystring("trackname") & "' and racedate =...
2
by: MLH | last post by:
Take a look at the code that follows. Line 110 is the beginning of Do-Loop. Regarding line #220, I find that I'm getting Error #3021 (No Current Record) during execution of line #230. It puzzles me...
15
by: shannon | last post by:
Hello, I am wondering if a Do until loop can be used in Javascript. I have an array and want to fill the array 10 times with the users details until it reaches 10 or if they press cancel. I'm...
4
by: Madhavi | last post by:
Hi Is there any Do Until Loop in C# Maadhavi
0
by: SyGC | last post by:
Hi Guys, I have used Threading for Network.Ping to continuously ping an IP address if ping is successful Image A is displayed if not Image B. The code is as follows: Imports System Imports...
5
by: SyGC | last post by:
Greetings All, I have established a working Remote Connection to a MySQL DB using ODBC which allows me to select data in a Datagridview in my Form. The data is a list of IP addresses. What i want...
2
by: Jerry Spence1 | last post by:
In VB2005 (.NET 2.0) when I do: my.computer.network.uploadfile I get the error "The requested FTP command is not supported when using an HTTP Proxy" Is there any way round this? Does this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.