So to solve that problem heres a cleaner clear cut API based function which will get the result done faster and more efficiently without alot of coding. Not only that its compact so you can easily add this to a module or do as I do and make it into a DLL.
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll"
Alias "InternetGetConnectedStateExA" (lpdwFlags As Long, lpszConnectionName As
Long, dwNameLen As Long, ByVal dwReserved As Long) As Long
Public Function Connected() As Boolean
Dim lNameLen As Long
Dim lRetVal As Long
Dim lConnectionFlags As Long
Dim LPTR As
Long
Dim lNameLenPtr As Long
Dim sConnectionName As String
sConnectionName = Space$(256)
lNameLen = 256
LPTR = StrPtr(sConnectionName)
lNameLenPtr = VarPtr(lNameLen)
lRetVal = InternetGetConnectedStateEx(lConnectionFlags, ByVal LPTR,
ByVal lNameLen, 0&)
Connected = (lRetVal <> 0)
End Function
The function will use the InternetGetConnectedState function in the wininet DLL file to see if your are connected to the internet. It will return TRUE if it is or FALSE if it isnt.
Comments