henryvii99
New Member
- Joined
- Apr 22, 2011
- Messages
- 32
Code:
Hello everyone,
I had found a way to quote real time prices from aastocks by the following user defined functions, by extracting the span class pos/neg/unc bold from the xml elements. For example, the price for
http://www.aastocks.com/en/ltp/rtquote.aspx?symbol=00008
is red, therefore the span class id is "neg bold".
I had created 3 scripts to extract the span class for positive price, negative price and unchanged price separately, using the following scripts:
For rising (positive) price:
[CODE]Public Function stockpos(ByVal dm As String) As String
On Error GoTo er
Set xlhttp = CreateObject("Msxml2.XMLHTTP")
With xlhttp
.Open "get", "http://www.aastocks.com/sc/ltp/rtquote.aspx?symbol=" & dm & "&time=" & Timer, False
.send
stockpos = Split(Split(StrConv(.responsebody, vbUnicode), "<span class=""pos bold"">")(1), "<")(0)
End With
Set xlhttp = Nothing
Exit Function
er:
stockpos = "err"
End Function
For negative (falling)) price:
Code:
Public Function stockneg(ByVal dm As String) As String
On Error GoTo er
Set xlhttp = CreateObject("Msxml2.XMLHTTP")
With xlhttp
.Open "get", "http://www.aastocks.com/sc/ltp/rtquote.aspx?symbol=" & dm & "&time=" & Timer, False
.send
stockneg = Split(Split(StrConv(.responsebody, vbUnicode), "<span class=""neg bold"">")(1), "<")(0)
End With
Set xlhttp = Nothing
Exit Function
er:
stockneg = "err"
End Function
And unchanged price:
Code:
Public Function stockunc(ByVal dm As String) As String
On Error GoTo er
Set xlhttp = CreateObject("Msxml2.XMLHTTP")
With xlhttp
.Open "get", "http://www.aastocks.com/sc/ltp/rtquote.aspx?symbol=" & dm & "&time=" & Timer, False
.send
stockunc = Split(Split(StrConv(.responsebody, vbUnicode), "<span class=""unc bold"">")(1), "<")(0)
End With
Set xlhttp = Nothing
Exit Function
er:
stockunc = "err"
End Function
The problem is I have to ask VB to search for the correct price span id. e.g. if the price is rising, the UDF for falling price and unchanged price will give me a percentage from somewhere apart from the real time quote (which is unwanted), or error message Therefore Excel spends most of the time updating unwanted data for me. And I have to set formula to extract the correct numerical result.
I think the 3 scripts can be combined into one, with the following priority:
1. If the span class id "pos bold" gives a numerical number, report;
2. If the span class id "pos bold" gives a number with % character or err, search for "neg bold" and report the numerical number;
3. If the span class id "neg bold" gives a number with % character or err, search for "unc bold" and report the numerical number.
Can anyone help? I know it may be challenging, many thanks in advance.