473,765 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

My.Computer.net work.ping Do Until Loop

17 New Member
Hi People,

Im trying to do a simple Loop where by an IP address is pinged (Using My.computer.net work.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 11874
jagged
23 New Member
Hi People,

Im trying to do a simple Loop where by an IP address is pinged (Using My.computer.net work.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.Threadin g.Thread.Sleep( 1000)
Feb 23 '08 #2
SyGC
17 New Member
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 New Member
Where is this code? Is it in the form_load event?

Did you include the Application.DoE vents()? 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
15680
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 said can someone please help me understand why this does not work? Dim x As String Private Sub cmdlogin_Click() Do Until x = "Corey" If txtlogin = "Corey" Then
1
1902
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
5835
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 = '" & request.querystring("racedate");" Set rs1 = Server.CreateObject("ADODB.Recordset") rs1.Open sqlstr,pConn,3
2
1792
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 as to Why? I thought if I was on last valid record of RecSet when line #220 executes, I would be sent to process lines after line #400. Am I wrong about that? ==> BEGIN CODE SNIPPET <=== 110 Do Until RecSet.EOF StartAnew:
15
51855
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 using window.prompt to get user info. Any suggestions. Do { //ask user to input their details } while (myairline !=10);
4
143989
by: Madhavi | last post by:
Hi Is there any Do Until Loop in C# Maadhavi
0
1486
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 System.Diagnostics Imports System.Threading Public Class Form1
5
2322
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 to do is take each IP address, parse it to My.Computer.Network.Ping if the result returns false then the IP address is diaplayed in a TextBox1. If the result is true then the IP address is either disgarded or displayed in another TextBox field. ...
2
3687
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 command work in .NET 3.0? -Jerry
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.