PDA

View Full Version : Help for using MID and INSTR in source code!



JKB
08-01-2014, 01:36 AM
Hi guys! Trying something new, i would like to use some information from a source code (from yahoo.finance on some stocks).
To do this i've found out that i can use the instr to locate positions in the html string i've created (sHtml_Yahoofinance, contains the full source code). Now, what i would like to do is to "print" the truncated source code in my textbox (Textbox1) so that i can see what im doing!
This however is not going as smooth as i hoped for, it doesnt seem to change the source code one bit... Can you guys explain to me what im doing wrong?


Private Sub CommandButton1_Click()
Dim label_start As Label
label_start:
Dim objIE As Object: Set objIE = CreateObject("Internetexplorer.application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.Visible = False
On Error Resume Next
objIE.Navigate (My link - Cant display this due to forum-rules.)
Do
DoEvents
If Err.Number <> 0 Then
objIE.Quit
Set objIE = Nothing
GoTo label_start:
End If
'Loading the source code
Loop Until objIE.ReadyState = 4 '4 indicates that page is completely loaded
Dim sHtml_YahooFinance As String
sHtml_YahooFinance = objIE.Document.body.innerHTML
'parsing the html string
If InStr(sHtml_YahooFinance, "yfs_pp0_") > 0 Then
sHtml_YahooFinance = Mid(sHtml_YahooFinance, InStr(sHtml_YahooFinance, "yfs_pp0_"), sHtml_YahooFinance) 'I want it to truncate where "yfs_pp0_" is located.
UserForm1.TextBox1.Text = sHtml_YahooFinance 'here im printing in Textbox1 after the source code has been edited, i think...
End If
End Sub



If i look in Textbox1, i see the same result, whether i remove/keep the line where i truncate... Could anybody enlighten me?

Hope you have a good day!

JKB

JKB
08-01-2014, 01:41 AM
.... I found the error! It was a simple mistake, of course the ending point for the truncation should be = len(sHtml_Yahoofinance) and not just sHtml_yahoofinance!
I do not know how to delete a post, can anybody help me with that then? :P

JKB
08-01-2014, 01:56 AM
If however it is possible! I would like to ask, if you guys know a smart way to do a bunch of commands for each appearance i find of "yfs_pp0_" ? And how i can count the numbers of appearances? I was thinking something with a loop, but maybe there is a smarter way?

westconn1
08-01-2014, 02:10 AM
you can work with the html elements of the document, rather than just a string of the entire html


I was thinking something with a loop, but maybe there is a smarter way?possibly other ways, but hard to tell without page source, else a loop will do