VB NET Check internet connection
Check Internet Connection using VB 2010
![]() |
Using VB.NET to check Internet Connection status |
- 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 |
- Coding
In the following VB.NET Code I'm using two Functions to (Boolean) :
- Check internet connection using Computer.Network.Ping("google.com")
- Check internet connection Using stream = client.OpenRead("http://www.google.com")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 |
♥ Here are some online Visual Basic lessons and courses :
- Visual Basic .Net snippets collection
- Visual Basic .Net - How to check for the internet connection
- Visual Basic .Net - POP3 and Receiving E-mails
- Visual Basic .Net - Generate Random Combinations
- Visual Basic .Net - Play sounds on Button Click or Mouse Hover
- Visual Basic .Net - Progressbar control
- Visual Basic .Net Solution - The application failed to initialize
- Visual Basic .Net - Working with Database full example
- Visual Basic .Net - There is already an open DataReader associated
- Visual Basic .Net - SyBase Advantage Database [Add, Edit, Search, Delete and DataGridView]
- Visual Basic .Net - Free POS System Project Source Code