read html tag line by line and find a vlue

Posted on 2006-05-19
Last Modified: 2007-12-19
assuming i have
how to read line by line the index.htl and serch a vlue "TEST" in all line of documet htl, and when is found store in MY_VAR....
Question by:sal21
    LVL 23

    Expert Comment

    LVL 17

    Accepted Solution

    You can iterate through the actual DOM but because elements have children, you may run into duplicates. The below example only outputs text from elements that 1.) have no children and 2.) have an outerText attribute. It has flaws but is just an example. Still, it's much simpler than having to parse the HTML yourself for reliable values.

    'include reference to 'Microsoft HTML Object Library'
    Option Explicit
    Private Sub Command1_Click()
        'load DOM
        Dim doc1 As HTMLDocument
        Dim doc2 As HTMLDocument
        Set doc1 = New HTMLDocument
        Set doc2 = doc1.createDocumentFromUrl("", vbNullString)
        Do Until doc2.readyState = "complete"
        'iterate through DOM elements
        Dim obj As IHTMLElement
        For Each obj In doc2.All
            If (obj.children.length = 0) Then
                Dim txt As String
                txt = obj.getAttribute("outerText")
                If (txt <> vbNullString) Then
                    Debug.Print obj.tagName, " --- ", txt
                End If
            End If
    End Sub

    Author Comment

    hi zzzzzooc tks for code... but my rially qst is:

    NOTE: in this case the value are 1, 4 and 308 but in the content of tag the value can change because the page is dinamic, in other case find the value after:

    font-weight:bold">&nbsp;Pagine&nbsp;now is 1
    font-weight:bold">&nbsp;Pagine&nbsp;1&nbsp;di&nbsp;now is 4
    <td align="center" colspan="11" class="INFO">Totale fidi individuati:now is 308

    I have this page in html...

    How to find the value 1 and 4 in:

    <td WIDTH="25%" ALIGN="center"><font style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight:

    and to find the value 308:

    <td align="center" colspan="11" class="INFO">Totale fidi individuati:

    after store the value founded in var_1, var_4 and var_308

    LVL 1

    Expert Comment

    Not sure what you want me to do when the value is found... but heres a quick function that will search a string for another string, and if it's found, will return true.

    'This code requires nothing
    Function IsFound(ByVal sSource As String, ByVal sFind As String, Optional ByVal CaseSensitive As Boolean = True) As Boolean
    If InStr(1, IIf(CaseSensitive, sSource, LCase(sSource)), IIf(CaseSensitive, sFind, LCase(sFind))) Then IsFound = True
    End Function

    And a quick run-through the arguments:
    sSource :: The string you want to search
    sFind :: The string you want to check for
    CaseSensitive :: Whether the search is case sensitive or not. If you do not specify a value it will be assumed that the search is CaseSensitive

    Author Comment

    hI Brownhead tks foir code....
    Sorry but i would want to use in vba for excel and not rially in vb classic
    LVL 1

    Expert Comment

    hmm... I've never used VBA, but does the InStr function supported? If so, then you sould simpley say:

    'This code requires nothing
    If (InStr(1,String1,String2)>0) then MsgBox "Found" Else MsgBox "NotFound"

    String1 :: The string you are searching
    String2 :: The string you are searching for

    DOes that work at all? I'm going in somewhat blind but if this doesn't work I'll try to do a little googling :D

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction While answering a recent question ( 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…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    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…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    779 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