Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-06-11
4
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 total points
ID: 17389125
KingSencat, any update?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

721 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