We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,257 times

Related Categories

Are you connected to the web? - Are you connected to the web?

crispin

Are you connected to the web?

Put two command buttons on a form call them:
cmdConnected - tells you if you are connected
cmdWhatConn - tells you what connection method you use.

then paste the following code into the form and run the project...

Option Explicit

Private Enum ConType
   LAN = 1
   MODEM = 2
   NONE = 3
   ALREADY = 4
End Enum
Private Const INTERNET_CONNECTION_LAN As Long = &H2
Private Const INTERNET_CONNECTION_MODEM As Long = &H1
Private Declare Function InternetGetConnectedState _
Lib "wininet.dll" (ByRef lpSFlags As Long, _
ByVal dwReserved As Long) As Long

Private Function ViaLAN() As Boolean

Dim SFlags As Long
'return the flags associated with the connection
Call InternetGetConnectedState(SFlags, 0&)

'True if the Sflags has a LAN connection
ViaLAN = SFlags And INTERNET_CONNECTION_LAN

End Function
Private Function ViaModem() As Boolean

Dim SFlags As Long
'return the flags associated with the connection
Call InternetGetConnectedState(SFlags, 0&)

'True if the Sflags has a modem connection
ViaModem = SFlags And INTERNET_CONNECTION_MODEM

End Function

Private Function Online() As Boolean
   'If you are online it will return True, otherwise False
   Online = InternetGetConnectedState(0&, 0&)
End Function

Private Sub cmdConnected_Click()
If Online Then
   MsgBox "Yes you are!", vbOKOnly, "ConnInfo"
Else
   MsgBox "Not at the moment", vbOKOnly, "ConnInfo"
End If
End Sub

Private Sub cmdWhatConn_Click()
If ViaModem Then
   MsgBox "You use a Modem", vbOKOnly, "ConnInfo"
ElseIf ViaLAN Then
   MsgBox "You use a LAN Connection", vbOKOnly, "ConnInfo"
Else
   MsgBox "I'm not quite sure?", vbOKOnly, "ConnInfo"
End If
End Sub

Comments