[AccessD] Read contents of Text File form Web Site

Gustav Brock Gustav at cactus.dk
Tue Feb 22 10:38:01 CST 2005


Hi Darren and Andy

Here's some code to read the file off the web server using winnet.dll:

Option Compare Database
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
  ByVal pCaller As Long, _
  ByVal szURL As String, _
  ByVal szFileName As String, _
  ByVal dwReserved As Long, _
  ByVal lpfnCB As Long) _
  As Long

Private Declare Function InternetGetConnectedState Lib "wininet.dll" ( _
  ByRef lpSFlags As Long, _
  ByVal dwReserved As Long) _
  As Long
  
  Const INTERNET_CONNECTION_MODEM = 1
  Const INTERNET_CONNECTION_LAN = 2
  Const INTERNET_CONNECTION_PROXY = 4
  Const INTERNET_CONNECTION_MODEM_BUSY = 8
  Const INTERNET_RAS_INSTALLED = 16

' Atomic clock.
Private Declare Sub InternetCloseHandle Lib "wininet.dll" ( _
  ByVal hInet As Long)
  
Private Declare Function InternetOpenA Lib "wininet.dll" ( _
  ByVal sAgent As String, _
  ByVal lAccessType As Long, _
  ByVal sProxyName As String, _
  ByVal sProxyBypass As String, _
  ByVal lFlags As Long) _
  As Long
  
Private Declare Function InternetOpenUrlA Lib "wininet.dll" ( _
  ByVal hOpen As Long, _
  ByVal sUrl As String, _
  ByVal sHeaders As String, _
  ByVal lLength As Long, _
  ByVal lFlags As Long, _
  ByVal lContext As Long) _
  As Long
  
Private Declare Sub InternetReadFile Lib "wininet.dll" ( _
  ByVal hFile As Long, _
  ByVal sBuffer As String, _
  ByVal lNumBytesToRead As Long, _
  ByRef lNumberOfBytesRead As Long)
'
Public Function OpenURL( _
  ByVal URL As String, _
  Optional ByVal OpenType As Long) _
  As String
  
  Const IOTPreconfig  As Long = 0
  Const IOTDirect     As Long = 1
  Const IOTProxy      As Long = 3

  Const INET_RELOAD = &H80000000
  
  Dim hInet As Long
  Dim hURL As Long
  Dim Buffer As String * 2048
  Dim Bytes As Long
  
  Select Case OpenType
    Case IOTPreconfig, IOTDirect, IOTProxy
      ' OK
    Case Else
      Exit Function
  End Select
  
  'Inet-Connection öffnen:
'  hInet = InternetOpenA("VB-Tec:INET", OpenType, vbNullString, vbNullString, 0)
'  hInet = InternetOpenA("Cactus:INET", OpenType, vbNullString, vbNullString, 0)
  hURL = InternetOpenUrlA(hInet, URL, vbNullString, 0, INET_RELOAD, 0)
  
  'Daten sammeln:
  Do
    InternetReadFile hURL, Buffer, Len(Buffer), Bytes
    If Bytes = 0 Then Exit Do
    OpenURL = OpenURL & Left$(Buffer, Bytes)
  Loop
  
  'Inet-Connection schließen:
  InternetCloseHandle hURL
  InternetCloseHandle hInet

End Function

/gustav

> What code do I need to read that text file from the website and return the
> Contents of the text file to my dB? Ie the -1 or the Zero?





More information about the AccessD mailing list