PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Web Data Retrieval
Retrieving information from the web and displaying in your own format is relatively easy with VB6's Internet Transfer object. Whether the target web document is a web page, text file, word doc or whatever, simply passing the URL of the file, is all that's required to pull back the entire file. The code below, shows an example of retrieving a web page and saving it as a text file:
  Dim strURL As String
  Dim bytData() As Byte 
  Dim intFile As Integer 
  Dim dblShell As Double

  strURL = "http://www.pbdr.com/index.html"
  intFile = FreeFile()
  
  bytData() = netTransfer.OpenURL(strURL, icByteArray)

  Open "c:\temp\webpage.txt" For Binary Access Write As #intFile
     Put #intFile, , bytData()
  Close #intFile

  dblShell = Shell("notepad c:\temp\webpage.txt")
In this example, a web page is identified and retrieved into a byte array using the Internet Transfer object, netTransfer. A byte array is used here because the target file can can download irrespective of it's type, be it an exe, doc, xls, rtf, htm, zip or txt. Here, the array holds the individual ascii values for each character in the web page source code. For ease of reading, the array is then converted into a flat file and subsequently displayed in notepad. Alternatively, the byte array could be looped through and a string constructed using an ascii to character conversion. The example has many applications, especially where web pages are regularly updated with important data, such as share details, sports results or new articles on pbdr.com, of course! The ability to search through the newly created text file (or string) , then lends itself to any specific information retrieval. One example could be to use this method to retrieve share info at work, without blatantly surfing financial pages - not that I would ever endorse such behavior.
 

Top of Page

Legal Notice

Ken Howe 2011