|
Another Stock quote application
In this particular example we are again going
to display stock quotes from Yahoo . This is slightly different
because it retrieves the quotes in csv format the stores the
results in an array and then we display a table with the information
. This is an improvement over our displaying
csv file example which required that the csv file had to
be downloaded on to the server .
This does not require this and accesses the file via yahoo's
web site . One drawback is that this requires the usage of the
Microsoft XMLHttp component .
Code:
<%
Dim objXML , strURL , strQuote
'create an instance of the XMLHTTP component
'old version of XML component
'Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
'get what the user entered in the form
strQuote = Request.Form("quote")
'build up the url and store it in strURL variable
strURL ="http://finance.yahoo.com/d/quotes.csv?s=msft&f=sl1d1t1c1ohgv&e=.csv"
'get the strURL
objXML.Open "GET" , strURL , False ,"",""
'send the information
objXML.Send
'if we have no errors
If Err.Number = 0 Then
'and the url is valid
If objXML.Status = 200 then
'store all of the downloaded data in strOpen
strOpen = objXML.ResponseText
'split the strOpemn into an array
arrText = split(strOpen, ",", 9)
Else
'bad url display a message
Response.Write "Incorrect URL"
End if
Else
'if we do have an error display the description of the error
Response.Write Err.Description
End If
'clear up
Set objXML = Nothing
%>
<table>
<tr><td>description</td><td>latest figure</td><tr>
<tr><td>symbol</td><td><%= arrText(0)
%></td></tr>
<tr><td>last price</td><td><%= arrText(1)
%></td></tr>
<tr><td>date</td><td><%= arrText(2)
%></td></tr>
<tr><td>time</td><td><%= arrText(3)
%></td></tr>
<tr><td>change</td><td><%= arrText(4)
%></td></tr>
<tr><td>open</td><td><%= arrText(5)
%></td></tr>
<tr><td>high</td><td><%= arrText(6)
%></td></tr>
<tr><td>low</td><td><%= arrText(7)
%></td></tr>
<tr><td>volume</td><td><%= arrText(8)
%></td></tr>
</table>
|