Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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

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
KingSencat
Asked:
KingSencat
  • 2
  • 2
1 Solution
 
David LeeCommented:
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
 
YoukkoCommented:
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
 
YoukkoCommented:
Is your question answered?!
0
 
David LeeCommented:
KingSencat, any update?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now