|
Displaying a CSV file
In this example we will show you how to display
the information in a CSV file . The best example of this are
the stock quotes from yahoo which can be downloaded in CSV format
.
Now once we have got our file which is usuallly called quotes.csv
, opening reveals it looks like this "MSFT",61.75,"10/29/2001","9:48AM",-0.45,62.10,62.21,61.55,2468700
.
A bit of a muddle isnt it , a bit of investigation reveals that
the data is in fact ticker symbol, last price, date, time, change,
open price, daily high, daily low, and volume . So what we need
to do is seperate the numbers and display them . Well here goes
.
Code :
<%
'declare our variables
Dim objFSO , strURL , objFile
'create an instance of the file system object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'this is the csv file downloaded from yahoo
strURL = Server.MapPath("quotes.csv")
'open the file
Set objFile = objFSO.OpenTextFile(strURL)
'while we are not at the end of the file
Do While Not objFile.AtEndOfStream
'store the contents of the file in strText
strText = objFile.readLine
'split the strText
arrText = split(strText, ",", 9)
Loop
'close and destroy objects
objFile.Close
Set objFile = Nothing
Set objFSO = 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>
Download :
quotes.csv the file used in
this example.
|