CodeItBetter Programming Another VB Programming Blog

How to check whether you are connected with internet

Posted on September 2, 2009

On your projects, you might require to know whether you are connected with Internet. So that you can decide to connect the internet or not. There are few ways to check whether you are connected to internet or now. Here is one of the way.

This piece of VB 6 code will help you to accomplish that.

Instructions:

  • Create a new Project
  • Add a new Module to it

Now, add the following code to that module:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Option Explicit
 
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Public Const INTERNET_CONNECTION_OFFLINE As Long = &H20
Public Const INTERNET_CONNECTION_CONFIGURED As Long = &H40
Public Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8
Public Const INTERNET_RAS_INSTALLED As Long = &H10
 
Sub Main()
  If AmIOnline Then
    Call MsgBox("You are connected with internet.", vbInformation, App.Title)
  Else
    Call MsgBox("You are not connected with internet.", vbInformation, App.Title)
  End If
End Sub
 
Private Function AmIOnline() As Boolean
  AmIOnline = InternetGetConnectedState(0&, 0&)
End Function

Related posts:

  1. How to check whether the system is connected with internet (in two ways)
  2. How to Check whether Mouse exist or not
  3. How to Cascade Internet Explorer windows on the desktop
  4. How to Change Internet Explorer Start Page and Main Window Title
  5. How to Download file from Internet
  6. How to get the NumLock state whether it is on or off
  7. How to Monitor the connection to the internet
  8. How to Download a file from the Internet — without getting a dialog box (in two ways)
  9. How to display what URL Internet Explorer/Netscape is displaying
  10. How to call IE’s Internet Options from VB

Comments (1) Trackbacks (0)
  1. how can i call it
    but thank u 4 all


Leave a comment


Trackbacks are disabled.