Are you connected to the web?

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

You might also like...

Comments

 crispin

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Every language has an optimization operator. In C++ that operator is ‘//’”