Results 1 to 5 of 5

Thread: how can I check if there is an internet connection?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    22
    I'm writing an HTML parser... I need my program to be able to check if there is an internet conection before it tries to download any html, how do I do this?

  2. #2
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    Hi

    Code:
    Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        If InternetAttemptConnect(ByVal 0&) = 0 Then
            MsgBox "You can connect to the Internet", vbInformation
        Else
            MsgBox "You cannot connect to the Internet", vbInformation
        End If
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    22

    Hi too you too

    I'm not sure that's what I'm after... I need to check if the computer is already connected, and if not, prompt the user to connect first

    does that code do that? or is it for checking if the computer can connect at all to the internet?

  4. #4
    calenkl
    Guest

    Talking InternetAttemptConnect

    i got this from the MSDN OCT 2000...

    Function:
    Attempts to make a connection to the Internet.

    Remark:
    This function allows an application to first attempt to connect before issuing any requests. A client program can use this to evoke the dial-up dialog box. If the attempt fails, the application should enter offline mode.

    so...if it returns fails...
    u can evoke the dial-up for the user...or
    urge ur user to connect first....

    there r some more APIs that u can use to perform this checking...

    i attached one module to u n try....there r three ways to check if u r connected....

    check with the Attachment...

    Hope it helps !!
    Attached Files Attached Files

  5. #5
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Maybe:

    Checks for active internet connection

    Code:
    'Author: Hutchie
    'Origin: http://www.vb-world.net/tips/tip467.html
    'Purpose: Check If there's an active internet connection
    'Version: VB5+
    
    Option Explicit
    
    Private Declare Function InternetGetConnectedState _
    Lib "wininet.dll" (ByRef lpSFlags As Long, _
    ByVal dwReserved As Long) As Long
    
    Private Const INTERNET_CONNECTION_LAN As Long = &H2
    Private Const INTERNET_CONNECTION_MODEM As Long = &H1
    
    Public Function Online() As Boolean
        'If you are online it will return True, otherwise False
        Online = InternetGetConnectedState(0&, 0&)
    End Function
    
    Public 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
    Public 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

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