VB NET Check internet connection

 Check Internet Connection using VB 2010

Using VB 2010 Check for Internet Connection
Using VB.NET to check Internet Connection status
This is a very simple example of how to check if there is an internet connection available for your machine (LapTop, PC) using VB 2010 Programming Language.

- Project Design :

1) Create new project, (save it)
2) Create new Windows Application form (Form1)
3) Place a Label (Label1) and Timer (Timer1) on your Form (Form1).
VB.NET Check Internet Connection
VB.NET Check Internet Connection

- Coding

In the following VB.NET Code I'm using two Functions to (Boolean) :
  1. Check internet connection using Computer.Network.Ping("google.com")
  2. Check internet connection Using stream = client.OpenRead("http://www.google.com")
'Visual Basic Online Courses
'VB.Net How to check internet connectivity
'Create new Form [Form1], place [Timer1],[Label1] Controls on Form1.
Public Class Form1
Function IsConnected() As Boolean
'Checks the internet connection
If My.Computer.Network.Ping("google.com").ToString = True Then
Label1.Text = ("Connected")
Label1.ForeColor = Color.Green
Else
Label1.Text = ("No Connection")
Label1.ForeColor = Color.Red
End If
Return True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
'Check if there is an internet connection is available.
IsConnected()
End Sub
'Another function to check for internet connectivity
Public Function CheckForInternetConnection() As Boolean
Try
Using client = New WebClient()
Using stream = client.OpenRead("http://www.google.com")
Return True
End Using
End Using
Catch
Return False
End Try
End Function
End Class
view raw gistfile1.vb hosted with ❤ by GitHub


Popular posts from this blog

VB .NET DropBox Api Source Code Example

VB .NET Google Drive Api Source Code Example

VB.NET Access 2007 Hierarchical TreeView

VB.NET How to properly close a windows application Form

DAO in VB .NET MS ACCESS Database

Solution - There is already an open DataReader associated with this Command which must be closed first.