Results 1 to 5 of 5

Thread: [RESOLVED] how to know the internet connection is available or not?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    59

    Resolved [RESOLVED] how to know the internet connection is available or not?

    hi guys

    I#m new in VB and this forum..

    I have question about, the synbtax to recognize an internet connection.

    so, I want to make a program that automatically start when the internet is online or when its connected to the LAN..

    can u guys help me with the syntax necessary?

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: how to know the internet connection is available or not?

    One API call:

    Declarations:

    VB Code:
    1. 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

    Code Neccessary:
    VB Code:
    1. If InternetCheckConnection("http://www.google.com/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
    2.         MsgBox "Connection to google failed!", vbInformation
    3.     Else
    4.         MsgBox "Connection to google succeeded!", vbInformation
    5.     End If

    That should do it.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    59

    Re: how to know the internet connection is available or not?

    but that means, if the LAN available but the internet does not, it will have failed message..

    I was thinking about checking the activities in komputer port. or there is much more simple way to do it?

    where can i find the documentation of that function?

    thanks

  4. #4
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: how to know the internet connection is available or not?

    That should tell you if you are connected to a network. It will also tell you which type.

    VB Code:
    1. Const NETWORK_ALIVE_AOL = &H4
    2. Const NETWORK_ALIVE_LAN = &H1
    3. Const NETWORK_ALIVE_WAN = &H2
    4. Private Declare Function IsNetworkAlive Lib "SENSAPI.DLL" (ByRef lpdwFlags As Long) As Long
    5. Private Sub Form_Load()
    6.    
    7.     Dim Ret As Long
    8.     If IsNetworkAlive(Ret) = 0 Then
    9.         MsgBox "The local system is not connected to a network!"
    10.     Else
    11.         MsgBox "The local system is connected to a " + IIf(Ret = NETWORK_ALIVE_AOL, "AOL", IIf(Ret = NETWORK_ALIVE_LAN, "LAN", "WAN")) + " network!"
    12.     End If
    13. End Sub
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    59

    Re: how to know the internet connection is available or not?

    ok bro now i understand now.. thank you a lot for helping me..
    thanks

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