Results 1 to 6 of 6

Thread: VB Snippet - Internet Status

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - Internet Status

    VB Code:
    1. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    2.  
    3. Private Const FLAG_ICC_FORCE_CONNECTION = &H1
    4.  
    5. Private Sub Form_Load()
    6.  
    7.     If InternetCheckConnection("http://www.galahtech.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
    8.  
    9.         MsgBox "No internet connection detected...", vbInformation
    10.  
    11.     Else
    12.  
    13.         MsgBox "Internet connection detected...", vbInformation
    14.  
    15.     End If
    16.  
    17. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    VB Code:
    1. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpSFlags As Long, ByVal dwReserved As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4. If InternetGetConnectedState(0, 0) Then
    5.     MsgBox "Online"
    6. Else
    7.     MsgBox "Offline"
    8. End If
    9. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    VB Code:
    1. 'Example by Vijay Phulwadhawa (vijaycg44@hotmail.com)
    2. Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
    3. Dim sConnType As String * 255
    4. Private Sub Form_Load()
    5.     Dim Ret As Long
    6.     Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
    7.     If Ret = 1 Then
    8.         MsgBox "You are connected to Internet via " & sConnType, vbInformation
    9.     Else
    10.         MsgBox "You are not connected to internet", vbInformation
    11.     End If
    12. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.   Screen.MousePointer = vbHourglass
    5.   With Winsock1
    6.     .Protocol = sckTCPProtocol
    7.     .RemotePort = 80
    8.     .RemoteHost = "www.vbforums.com"
    9.     .Connect
    10.    
    11.     Do While .State <> sckConnected And .State <> sckError
    12.       DoEvents
    13.     Loop
    14.     If .State = sckConnected Then
    15.       Caption = "Online"
    16.     Else
    17.       Caption = "Offline"
    18.     End If
    19.     .Close
    20.     .LocalPort = 0
    21.   End With
    22.   Screen.MousePointer = vbDefault
    23. End Sub
    Last edited by manavo11; Aug 23rd, 2003 at 09:33 PM.


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: VB Snippet - Internet Status

    Quote Originally Posted by James Stanich
    VB Code:
    1. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    2.  
    3. Private Const FLAG_ICC_FORCE_CONNECTION = &H1
    4.  
    5. Private Sub Form_Load()
    6.  
    7.     If InternetCheckConnection("http://www.galahtech.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
    8.  
    9.         MsgBox "No internet connection detected...", vbInformation
    10.  
    11.     Else
    12.  
    13.         MsgBox "Internet connection detected...", vbInformation
    14.  
    15.     End If
    16.  
    17. End Sub
    Will the above code work if user is connected via LAN?
    Thanx, Shiraz
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB Snippet - Internet Status

    It should. If there is an active internet connection then a connection to the site will be made.


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width