Solved

500 Points , I am using WebBrowser in my vb6.0 application and ...

Posted on 2006-06-11
4
194 Views
Last Modified: 2010-04-30
Hi experts!


I am using webbrowser in my vb6.0 application and i want to take just 1 number from " http://www.counterdata.com/details.php?page=98395 " see on "Total Hits     24 " <-- i want only to took the number (24)  and then showing back to my application box name "results". I dont want to use MSINET , i want to do it using webbrowser.


thanks a lot, i hope is possible.
0
Comment
Question by:KingSencat
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17028524
You can use something like this.  Having gotten the page you'll need to parse the page elements until you find the one you need.

Private Sub Command1_Click()
    Dim objHTMLDoc As HTMLDocument, _
        objElements As IHTMLElementCollection, _
        objElement As IHTMLElement
    WebBrowser1.Navigate2 "http://www.counterdata.com/details.php?page=98395"
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    Set objHTMLDoc = WebBrowser1.Document
    Set objElements = objHTMLDoc.All
    For Each objElement In objElements
        'Code to detect and get the value you need
    Next
End Sub
0
 
LVL 1

Expert Comment

by:Youkko
ID: 17185474
Well... I've done a code without using the WebBrowser Control... Tested it myself, and it worked fine.
If you don't mind the fact that it doesn't use the Webbrowser, you can test it...
Just put a TextBox on a form, name it "Text1", and paste the following code...

I really hope it helps you!

'---------------------------------------------------------------------------
Option Explicit

Private Const ERROR_SUCCESS As Long = 0
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 DeleteUrlCacheEntry Lib "Wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long

Private Sub Form_Load()
Text1.Text = FilterSource(GetCounterData)
End Sub

Private Function GetCounterData() As String
    Dim strURL As String
    Dim tempFile As String
    Dim myFile As Long
    Dim buffer As String
   
    'Target URL
     strURL = "http://www.counterdata.com/details.php?page=98395"
     
     'Local file used to store data
     tempFile = App.Path & "\hits.txt"
   
    'Remove the URL from cache if exists, so we are sure to get
    'only fresh data
     Call DeleteUrlCacheEntry(strURL)
   
    'Download the source code from the URL to the file
     If DownloadFile(strURL, tempFile) Then
        myFile = FreeFile
        Open tempFile For Input As #myFile
           buffer = Input$(LOF(myFile), myFile)
        Close #myFile
        'read the buffer
        GetCounterData = buffer
        'remove temp file
        Kill tempFile
    Else
        'If download fails, return ERR.1 so you can deal with it
        GetCounterData = "ERR.1"
    End If
End Function

Private Function DownloadFile(ByVal sURL As String, ByVal tempFile As String) As Boolean
   DownloadFile = URLDownloadToFile(0, sURL, tempFile, 0, 0) = ERROR_SUCCESS
End Function

Private Function FilterSource(sourceData As String) As String
   Dim X As Long, Y As Long
   Dim strFind_A As String, strFind_B As String
   Dim posStr_A As Long, posStr_B As Long
   Dim Ripd As String, Numbers As String, Result As String
   
   'Strings you want to find on the code
   strFind_A = "Total Hits"
   strFind_B = "Hits Today"
   
   'Counter
   X = 1
   
   'Find the position of the two strings on the sourceData
   Do While X < (Len(sourceData) - Len(strFind_A))
        If UCase(Mid(sourceData, X, Len(strFind_A))) = UCase(strFind_A) Then
            posStr_A = X
            Exit Do
        End If
        DoEvents
        X = X + 1
   Loop
   Do While X < (Len(sourceData) - Len(strFind_B))
        If UCase(Mid(sourceData, X, Len(strFind_B))) = UCase(strFind_B) Then
            posStr_B = X
            Exit Do
        End If
        DoEvents
        X = X + 1
   Loop
   
   'Get the data between the two strings
   Ripd = Mid(sourceData, (posStr_A + Len(strFind_A)), ((posStr_B - posStr_A) - Len(strFind_B)))
   
   'Remove any non-numeric characters from Ripd
   Numbers = "0123456789"
   Result = ""
   X = 1
   Do While X <= Len(Ripd)
       Y = 1
       Do While Y <= Len(Numbers)
           If Mid(Ripd, X, 1) = Mid(Numbers, Y, 1) Then
               Result = Result & Mid(Ripd, X, 1)
               Exit Do
           End If
           DoEvents
           Y = Y + 1
       Loop
       DoEvents
       X = X + 1
   Loop
   FilterSource = Result
End Function
0
 
LVL 1

Expert Comment

by:Youkko
ID: 17334584
Is your question answered?!
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 17389125
KingSencat, any update?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 59
Access 2016 VB code 9 86
Excel object stays open 19 65
Put text in a picture ASP.NET C# 2 37
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now