Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004

    Cool Unanswered: VB6 open a web page

    Hi All-

    So, I need a Function that will do the following:
    1) Open a static URL (in the background, no user intervention, user sees nothing).
    2) Read the "Body" from the HTML File (which will only contain a number such as 2.23)
    3) Store that value into a variable (txtNumber)
    4) Close the URL (if still open)

    My txtNumber is going to be a public variable... so here's the question...
    how do i do this!?

    I've scoured the net and found some information on WebBrowser Controls and the like, but I'd like to think its easier than that. Open a page (visible = false), txtNumber.Text = HTML "BODY", Close page.... is basically what I need.

    Any ideas or thoughts on how I could get started? I'm not neccessarily looking for all the code, but could use a little help. I have no idea what type of control to even use!


    update: if its easier, i could even have it read the HTML pages Title Page, Meta Tag, or whatever is easiest. Or I could make it a text page on my website and go from there... i'm looking for easiest/least code
    Last edited by mateo107; 11-21-04 at 16:47. Reason: update
    -Matt H-

  2. #2
    Join Date
    May 2004
    Try this from the API Guide...

    Const scUserAgent = "API-Guide test program"
    Const INTERNET_FLAG_RELOAD = &H80000000
    Const sURL = ""
    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
    Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    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
    Private Sub Form_Load()
    'KPD-Team 1999

    Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    'Create a buffer for the file we're going to download
    sBuffer = Space(1000)
    'Create an internet connection
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    'Open the url
    hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    'Read the first 1000 bytes of the file
    InternetReadFile hFile, sBuffer, 1000, Ret
    'clean up
    InternetCloseHandle hFile
    InternetCloseHandle hOpen
    'Show our file
    MsgBox sBuffer
    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