ANmaNumber_Closest2Word

Finds the number between two spaces that is found close to of Word1Location that is closest to Word1Location.
Part of reading number values from HTML page output.
Pass 3 variables, location of word to search number next to it, what is that word, and of course the full HTML page or block to search in.
Number has to have comma inside it.
Search before the word, if not find, search after the word.
Stop search if we found > or ; before the word, or < or ; after the word.

This is one of my advanced complicated functions here.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function ANmaNumber_Closest2Word(Word1Location, Word1, Page7)
    ' Finds the number between two spaces that is found close to of Word1Location that is closest to Word1Location
    ' Number has to have comma inside it
    ' Search before the word, if not find, search after the word
    ' Stop search if we found > or ; before the word, or < or ; after the word
    '
    Rett = ""
    Page8 = ExtractHTMLArea(Word1Location, Page7) ' Return the TD where we found Word1Location in
    Word1L2 = VBInstr(Word1, Page8)
    WordFound = 0
    Space1 = 0
    For I = Word1L2 To 1 Step -1
        If UCase(Mid(Page8, I, Len(Word1))) = UCase(Word1) Then
            WordFound = I
            Exit For
        End If
    Next
    If WordFound = 0 Then GoTo ByeBye
    For I = WordFound To 1 Step -1
        If Mid(Page8, I, 1) = " >" Or Mid(Page8, I, 1) = ";" Then Exit For
        If Mid(Page8, I, 1) = " " Then
            Space1 = I
            Exit For
        End If
    Next
    If Space1 = 0 Then GoTo SearchAfter
GetNextNum1:
    AmNum = 0
    For I = Space1 - 1 To 1 Step -1
        If Mid(Page8, I, 1) = " >" Or Mid(Page8, I, 1) = ";" Then Exit For
        If IsNumeric(Mid(Page8, I, 1)) Then
            AmNum = I
            Exit For
        End If
    Next
    If AmNum = 0 Then GoTo SearchAfter
    HaveComma = 0
    For I = AmNum To 1 Step -1
        If Mid(Page8, I, 1) = "," Then HaveComma = 1
        If Mid(Page8, I, 1) = " " Or Mid(Page8, I, 1) = " >" Then
            If HaveComma = 0 Then
                Space1 = I
                GoTo GetNextNum1
            End If
            Rett = Val(Replace(Mid(Page8, I, AmNum - I + 1), ",", ""))
            Exit For
        End If
    Next
    If IsNumeric(Rett) Then GoTo ByeBye
SearchAfter:
    For I = WordFound To Len(Page8)
        If Mid(Page8, I, 1) = " <" Or Mid(Page8, I, 1) = ";" Then Exit For
        If Mid(Page8, I, 1) = " " Then
            Space1 = I
            Exit For
        End If
    Next
    If Space1 = 0 Then GoTo ByeBye
GetNextNum2:
    AmNum = 0
    For I = Space1 To Len(Page8)
        If Mid(Page8, I, 1) = " <" Or Mid(Page8, I, 1) = ";" Then Exit For
        If IsNumeric(Mid(Page8, I, 1)) Then
            AmNum = I
            Exit For
        End If
    Next
    If AmNum = 0 Then GoTo ByeBye
    HaveComma = 0
    For I = AmNum To Len(Page8)
        If Mid(Page8, I, 1) = "," Then HaveComma = 1
        If Mid(Page8, I, 1) = " " Or Mid(Page8, I, 1) = " <" Then
            If HaveComma = 0 Then
                Space1 = I
                GoTo GetNextNum2
            End If
            Rett = Val(Replace(Mid(Page8, AmNum, I - AmNum + 1), ",", ""))
            Exit For
        End If
    Next
ByeBye:
    ANmaNumber_Closest2Word = Rett
End Function

Word1Location, Word1, Page7

Views 208

Downloads 63

CodeID
DB ID