|
-
May 5th, 2010, 10:52 AM
#1
Thread Starter
Member
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 & Time Clock'>Add Minutes & 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
-
May 5th, 2010, 10:53 AM
#2
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)
-
May 5th, 2010, 11:29 AM
#3
Lively Member
Re: Getting Website Text w/ strFindBetween Function [error!]
try this code:
vb Code:
dim a as long a = InStr(trimStrLine, strEndPoint) if a > 0 then trimStrLine = Mid$(trimStrLine, 1, a - 1) end if
-
May 5th, 2010, 11:43 AM
#4
Re: Getting Website Text w/ strFindBetween Function [error!]
Let me fix that for you 
 Originally Posted by claiyah
try this code:
vb Code:
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
Or you could coerce < 1 to a 1(or something else):
vb Code:
dim a as long
a = InStr(trimStrLine, strEndPoint) - 1
if a < 1 then a = 1 ' or maybe len(of_some_text)?
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.
-
May 5th, 2010, 12:11 PM
#5
Thread Starter
Member
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?
-
May 5th, 2010, 12:36 PM
#6
Re: Getting Website Text w/ strFindBetween Function [error!]
Basically:
vb 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!
Dim X As Long
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
X = InStr(trimStrLine, strStartPoint)
If X > 0 Then
trimStrLine = Mid$(trimStrLine, X + Len(strStartPoint))
Else
goto ErrNotFound
End If
Next skipInst
'Trim the line to the end of the second specified string
X = InStr(trimStrLine, strEndPoint) - 1
If X > 0 Then
trimStrLine = Mid$(trimStrLine, 1, X)
Else
goto ErrNotFound
End if
'Assign the string between the two given string-points
strFindBetween = trimStrLine
Exit Function
ErrNotFound:
'the function failed, do something about it here
End Function
Last edited by FireXtol; May 5th, 2010 at 02:44 PM.
-
May 5th, 2010, 12:56 PM
#7
Thread Starter
Member
Re: Getting Website Text w/ strFindBetween Function [error!]
lol doesnt work at all now, grabs a whole blob of text
-
May 5th, 2010, 02:43 PM
#8
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.
-
May 6th, 2010, 07:32 AM
#9
Thread Starter
Member
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!"
-
May 6th, 2010, 01:06 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|