Hey everyone,
I found the following piece of code somewhere, and was just
wondering if you guys (and girls) would check it out to see if
it works OK for you.
I need a good, reliable code to check to see if the computer is
connected to the Internet. It needs to work with cable modems,
dial-up modems, and networks.
I'm pretty sure this will work fine, but I sure would appreciate it
if you would check it out.
Thanks in advance,
Ron
*********************************************
*********************************************
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
If InternetCheckConnection("
http://www.yahoo.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "NOT Connected to the Internet!", vbInformation
Else
MsgBox "Connected to the Internet!", vbInformation
End If
End Sub
*********************************************
*********************************************
Comments
: Hey everyone,
:
: I found the following piece of code somewhere, and was just
: wondering if you guys (and girls) would check it out to see if
: it works OK for you.
:
: I need a good, reliable code to check to see if the computer is
: connected to the Internet. It needs to work with cable modems,
: dial-up modems, and networks.
:
: I'm pretty sure this will work fine, but I sure would appreciate it
: if you would check it out.
:
: Thanks in advance,
: Ron
:
:
: *********************************************
: *********************************************
:
: Private Const FLAG_ICC_FORCE_CONNECTION = &H1
:
: Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
:
:
: Private Sub Form_Load()
: If InternetCheckConnection("http://www.yahoo.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
: MsgBox "NOT Connected to the Internet!", vbInformation
: Else
: MsgBox "Connected to the Internet!", vbInformation
: End If
: End Sub
:
: *********************************************
: *********************************************
:
:
:
It is working on my computer.
I tested it while I was on line and it said it was connected, and then tested after I went offline using the File Menu of Internet Explorer and it said it wasn't connected. I haven't tested when my phone lines not connected as I don't want to make another phone call. I'll try it when I disconnect and get back to you tomorrow if it doesn't work, otherwise assume it worked. I think it would be pretty safe to assume that it's going to work when I'm totally connected anyway.
DjSpirit, I {am|am not} connected.[/grey]
[b][green]Koozime![/green][/b]
: [b][green]Koozime![/green][/b]
:
:
Maybe the way around that would be to check more than one site (Maybe 4 to 5). If all of the fail then its off line, then if one of them are OK then its online.
Although theres been occasions were my computers made a bad connection to the internet and won't load anything. So it would probably say its offline in this case too.