Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Full code for monitoring connection to the interne...
Author:
Foyal S. Carter, Jr.
E-mail:
Click to e-mail author
Submitted:
4/17/2000
Version:
VB5
Compatibility:
VB5, VB6
Category:
Internet Programming
Views:
15912
Full code for monitoring connection to the internet. Includes function to be called by a timer which returns true or false depending on the current connection state.
Declarations:
Const RAS95_MaxEntryName = 256 Const RAS95_MaxDeviceType = 16 Const RAS95_MaxDeviceName = 32 Private Type RASCONN95 dwSize As Long hRasCon As Long szEntryName(RAS95_MaxEntryName) As Byte szDeviceType(RAS95_MaxDeviceType) As Byte szDeviceName(RAS95_MaxDeviceName) As Byte End Type Private Type RASCONNSTATUS95 dwSize As Long RasConnState As Long dwError As Long szDeviceType(RAS95_MaxDeviceType) As Byte szDeviceName(RAS95_MaxDeviceName) As Byte End Type Private Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As Long) As Long Private Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long
Code:
'This function checks for a connection to the internet 'and returns true or false as to whether one is present Private Function CheckInternetConnection() As Boolean On Error GoTo ErrHandler Dim TRasCon(255) As RASCONN95 Dim lg As Long Dim lpcon As Long Dim RetVal As Long Dim Tstatus As RASCONNSTATUS95 TRasCon(0).dwSize = 412 lg = 256 * TRasCon(0).dwSize RetVal = RasEnumConnections(TRasCon(0), lg, lpcon) If RetVal <> 0 Then ' MsgBox "ERROR" Exit Function End If Tstatus.dwSize = 160 RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus) If Tstatus.RasConnState = &H2000 Then CheckInternetConnection = True Else CheckInternetConnection = False End If ExitCheckConnection: Exit Function ErrHandler: CheckInternetConnection = False Resume ExitCheckConnection End Function 'Set the timer interval to however many seconds you would 'like between checks * 1000 Private Sub Timer1_Timer() If CheckInternetConnection = True Then 'Do whatever you need to do when connected Else 'Do whatever you need to do when disconnected End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement