PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Getting Website Text w/ strFindBetween Function [error!]-VBForums
Results 1 to 10 of 10

Thread: Getting Website Text w/ strFindBetween Function [error!]

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    33

    Getting Website Text w/ strFindBetween Function [error!]

    Ok I am using a function that I found on this forum (its freakin great, I LOVE IT!) I have never had a problem with it up until now, basically the prodcedure its erroring on is when the program signs into employee's timeclock account, when it signs in, it needs to grab some dynamic text, as well as grab last 4 of social (which is done on the website the program goes to)

    Here is the strFindBetween Function

    Code:
    Public Function strFindBetween(strToSearch As String, strStartPoint As String, strEndPoint As String, Optional skipInstance As Integer = 0) As String
    'Quit the function if infomation provided doesn't fit requirements
    'Finds a string, between 2 strings good for grabbing aritlce text!
    If strToSearch = "" Or strStartPoint = "" Or strEndPoint = "" Then Exit Function
     If Not InStrB(strToSearch, strStartPoint) > 0 And InStrB(strToSearch, strEndPoint) > 0 Then Exit Function
     Dim trimStrLine As String
     Dim strResult As String
    Dim skipInst As Integer
    
    trimStrLine = strToSearch
    'Skip instances of first string; default doesn't skip
    For skipInst = 0 To skipInstance
    trimStrLine = Mid$(trimStrLine, InStr(trimStrLine, strStartPoint) + Len(strStartPoint))
    Next skipInst
    
    'Trim the line to the end of the second specified string
    trimStrLine = Mid$(trimStrLine, 1, InStr(trimStrLine, strEndPoint) - 1)
    
    'Assign the string between the two given string-points
    strFindBetween = trimStrLine
    End Function
    And here is the code for when the program logs in...

    Code:
    ElseIf InStr(S$, "title='Punch In &amp; Time Clock'>Add Minutes &amp; Hours</a>") <> 0 Then
    Stat "landed on main signin page, yeayay!"
    txtData.text = wOd1.Response.Body
    CompanyID$ = strFindBetween(txtData.text, "{ companyId: ", " },")
    Stat "grabbed company id [" & CompanyID$ & "]"
    wOd1.Get "http://www.rothco.com/UpdateDetails.aspx?Employee_PunchIn_NationalCO=ContactDetails&CompanyID=" & CompanyID$
    Stat "going to contact page for meh info!"
    ElseIf InStr(S$, "Contact Details for your listing") <> 0 Then
    Stat "landed on contact info page, scrapin it'"
    txtData.text = wOd1.Request.Body
    'BotAddy$ = strFindBetween(txtData.text, "GoogleMap.AddressLocator.Address                = '", "';")
    'BotName$ = strFindBetween(txtData.text, "ctl00$contentSection$ctrlContactDetails$txtBusinessName" & txtQ.text & " type=" & txtQ.text & "text" & txtQ.text & " value=" & txtQ.text, txtQ.text & " maxlength=" & txtQ.text & "150" & txtQ.text & " id=")
    'BotCity$ = strFindBetween(txtData.text, "ctl00$contentSection$ctrlContactDetails$txtSuburb" & txtQ.text & " type=" & txtQ.text & "text" & txtQ.text & "value=" & txtQ.text)
    'BotpNumber$ = strFindBetween(txtData.text, "ls$txtPhone" & txtQ.text & " type=" & txtQ.text & "text" & txtQ.text & " value=" & txtQ.text, txtQ.text & " maxlength=" & txtQ.text & "50" & txtQ.text & " id=" & txtQ.text & "ctl00_contentSection_ctrlContactDetails_txtPhone" & txtQ.text)
    'BotWebSite$ = strFindBetween(txtData.text, "ctl00$contentSection$ctrlContactDetails$txtWebsite" & txtQ.text & " type=" & txtQ.text & "text" & txtQ.text & " value=" & txtQ.text, txtQ.text & " maxlength=" & txtQ.text & "200" & txtQ.text & " id=" & txtQ.text & "ctl00_contentSection_ctrlContactDetails_txtWebsite")
    Pause 1
    BotEMail$ = strFindBetween(S$, "ctl00$contentSection$ctrlContactDetails$txtEmail" & txtQ.text & " type=" & txtQ.text & "text" & txtQ.text & " value=" & txtQ.text, txtQ.text & "maxlength=" & txtQ.text & " 100" & txtQ.text & " id=" & txtQ.text & "ctl00_contentSection_ctrlContactDetails_txtEmail")
    MsgBox BotAddy$ & vbNewLine & BotName$ & vbNewLine & BotCity$ & vbNewLine & BotpNumber$ & vbNewLine & BotWebSite$ & vbNewLine & BotEMail$
    End If
    Now the error I keep getting is Run-Time Error '5', Invalid procedure call or arguement. And highlights this code in the bas mod, under strFindBetween's function

    Code:
    trimStrLine = Mid$(trimStrLine, 1, InStr(trimStrLine, strEndPoint) - 1)
    Thats the line it highlights...any idea's I use this function for allot, whenever I need to grab text / strings off a webpage I have the page's source loaded in a textbox & then call this function or have the page's source be S$ and call the function w/ that. HELP! <3

  2. #2
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Getting Website Text w/ strFindBetween Function [error!]

    Instr is likely returning zero or 1.

    Instr's should really be set to a variable, and then the variable checked for being greater than 0 before you attempt to use it in Mid$(). (otherwise, you'll likely want to skip the mid$() all together)

  3. #3
    Lively Member claiyah's Avatar
    Join Date
    Apr 2010
    Location
    Tunisia
    Posts
    79

    Re: Getting Website Text w/ strFindBetween Function [error!]

    try this code:
    vb Code:
    1. dim a as long
    2. a = InStr(trimStrLine, strEndPoint)
    3. if a > 0 then
    4. trimStrLine = Mid$(trimStrLine, 1, a - 1)
    5. end if

  4. #4
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Getting Website Text w/ strFindBetween Function [error!]

    Let me fix that for you

    Quote Originally Posted by claiyah View Post
    try this code:
    vb Code:
    1. dim a as long
    2. a = InStr(trimStrLine, strEndPoint)
    3. if a > 1 then '2-1 = 1, while 1-1 = error
    4. trimStrLine = Mid$(trimStrLine, 1, a - 1)
    5. end if
    Or you could coerce < 1 to a 1(or something else):

    vb Code:
    1. dim a as long
    2. a = InStr(trimStrLine, strEndPoint)  - 1
    3. if a < 1 then a = 1 ' or maybe len(of_some_text)?
    4. trimStrLine = Mid$(trimStrLine, 1, a)

    But the data is probably faulty(or there's simply no more matches) if instr() returns zero.
    Last edited by FireXtol; May 5th, 2010 at 11:48 AM.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    33

    Re: Getting Website Text w/ strFindBetween Function [error!]

    Code:
    Public Function strFindBetween2(strToSearch As String, strStartPoint As String, strEndPoint As String, Optional skipInstance As Integer = 0) As String
    'Quit the function if infomation provided doesn't fit requirements
    'Finds a string, between 2 strings good for grabbing aritlce text!
    If strToSearch = "" Or strStartPoint = "" Or strEndPoint = "" Then Exit Function
     If Not InStrB(strToSearch, strStartPoint) > 0 And InStrB(strToSearch, strEndPoint) > 0 Then Exit Function
     Dim trimStrLine As String
     Dim strResult As String
    Dim skipInst As Integer
    Dim A As Long
    
    A = InStr(trimStrLine, strEndPoint)
    If A > 1 Then '2-1 = 1, while 1-1 = error
    trimStrLine = Mid$(trimStrLine, 1, A - 1)
    End If
    'Skip instances of first string; default doesn't skip
    For skipInst = 0 To skipInstance
    trimStrLine = Mid$(trimStrLine, InStr(trimStrLine, strStartPoint) + Len(strStartPoint))
    Next skipInst
    
    'Trim the line to the end of the second specified string
    trimStrLine = Mid$(trimStrLine, 1, InStr(trimStrLine, strEndPoint) - 1)
    
    'Assign the string between the two given string-points
    strFindBetween2 = trimStrLine
    End Function
    This gives me same EXACT error, did I implament your code correctly?

  6. #6
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Getting Website Text w/ strFindBetween Function [error!]

    Basically:

    vb Code:
    1. Public Function strFindBetween(strToSearch As String, strStartPoint As String, strEndPoint As String, Optional skipInstance As Integer = 0) As String
    2. 'Quit the function if infomation provided doesn't fit requirements
    3. 'Finds a string, between 2 strings good for grabbing aritlce text!
    4. Dim X As Long
    5. If strToSearch = "" Or strStartPoint = "" Or strEndPoint = "" Then Exit Function
    6.  If Not InStrB(strToSearch, strStartPoint) > 0 And InStrB(strToSearch, strEndPoint) > 0 Then Exit Function
    7.  Dim trimStrLine As String
    8.  Dim strResult As String
    9. Dim skipInst As Integer
    10.  
    11. trimStrLine = strToSearch
    12. 'Skip instances of first string; default doesn't skip
    13. For skipInst = 0 To skipInstance
    14.   X = InStr(trimStrLine, strStartPoint)
    15.   If X > 0 Then
    16.     trimStrLine = Mid$(trimStrLine, X + Len(strStartPoint))
    17.   Else
    18.     goto ErrNotFound
    19.   End If
    20. Next skipInst
    21.  
    22. 'Trim the line to the end of the second specified string
    23. X = InStr(trimStrLine, strEndPoint) - 1
    24. If X > 0 Then
    25.   trimStrLine = Mid$(trimStrLine, 1, X)
    26. Else
    27.   goto ErrNotFound
    28. End if
    29. 'Assign the string between the two given string-points
    30. strFindBetween = trimStrLine
    31. Exit Function
    32. ErrNotFound:
    33. 'the function failed, do something about it here
    34. End Function
    Last edited by FireXtol; May 5th, 2010 at 02:44 PM.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    33

    Re: Getting Website Text w/ strFindBetween Function [error!]

    lol doesnt work at all now, grabs a whole blob of text

  8. #8
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Getting Website Text w/ strFindBetween Function [error!]

    I have revised the function(edited the post), do with the failure of the function as you wish.

    Good luck.

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    33

    Re: Getting Website Text w/ strFindBetween Function [error!]

    You rock thanks FireXtol , the function you re-wrote works good, and I see where I went wrong.. Let's stamp this one --- "Resolved!"

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,020

    Re: Getting Website Text w/ strFindBetween Function [error!]

    In that case please click on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width