Results 1 to 4 of 4

Thread: Know if a URL is available

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    14

    Know if a URL is available

    Hello,

    I'm looking for a function that will say if a URL is available or not.

    I found this function :
    Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long

    But it works when the URL is available, when the computer is not connected but it freezes when the URL is not available !!!

    Do you know something that works ?!?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Know if a URL is available

    You might want to look at this thread, for PINGing the url

    http://www.vbforums.com/showthread.php?t=358598

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    14

    Re: Know if a URL is available

    Sorry. I didn't specify that i'm using Access. So I think i can't use this .net function. Do you have something else ?

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Know if a URL is available

    You might be able to use this in VBA. You might want to post there.
    It returns Null if the site is down.

    VB Code:
    1. Option Explicit
    2. Const scUserAgent = "API-Guide test program"
    3. Const INTERNET_OPEN_TYPE_DIRECT = 1
    4. Const INTERNET_OPEN_TYPE_PROXY = 3
    5. Const INTERNET_FLAG_RELOAD = &H80000000
    6. Const sURL = "http://www.microsoft.com/index.htm"
    7. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    8. Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long
    9. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    10. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    11. Private Sub Form_Load()
    12.     'KPD-Team 1999
    13.     'URL: [url]http://www.allapi.net/[/url]
    14.     'E-Mail: [email][email protected][/email]
    15.  
    16.     Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    17.     'Create a buffer for the file we're going to download
    18.     sBuffer = Space(1000)
    19.     'Create an internet connection
    20.     hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    21.     'Open the url
    22.     hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    23.     'Read the first 1000 bytes of the file
    24.     InternetReadFile hFile, sBuffer, 1000, Ret
    25.     'clean up
    26.     InternetCloseHandle hFile
    27.     InternetCloseHandle hOpen
    28.     'Show our file
    29.     MsgBox sBuffer
    30. End Sub

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