Display a CSV file
Display a CSV file
CSV files are common formats to get information . I have seen commission sites , stock quotes and various links in these types of files . CSV are comma seperated value files , the typical format of one of these could be like this.
1000,age,234,billy
This is not much to look at but with a little scripting we can make it more readable . In this example we have a stock quotes csv file downloaded from Yahoo which we wish to display.
<%
‘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>


















































