techpreparation-homepage

Home  Interview Questions  Aptitude Questions  Tutorials  Placement Papers  Search  Resume Guide  Soft Skills  Video  Forum  Blog


Technical Interview Questions

Visual Basic Interview Question
.NET Web Interview Questions
.NET Interview Questions
C# Interview Questions
                              .........More

Source Codes
Asp .NET Source Codes
Asp VB Script Source Codes
                              .........More

Soft Skills
Communication Skills
Leadership Skills
                              .........More

Subscribe to our Newsletters
Name:
Email:

 

 

  

Asp/VB Script Source Codes

Display CSV Files Using ASP

<P>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.</P>
<P>1000,age,234,billy</P>
<P>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.</P>
<P>&lt;%<BR>'declare our variables<BR>Dim objFSO , strURL , objFile<BR>'create an instance of the file system object<BR>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")<BR>'this is the csv file downloaded from yahoo<BR>strURL = Server.MapPath("quotes.csv")<BR>'open the file<BR>Set objFile = objFSO.OpenTextFile(strURL)<BR>'while we are not at the end of the file<BR>Do While Not objFile.AtEndOfStream<BR>'store the contents of the file in strText<BR>strText = objFile.readLine<BR>'split the strText <BR>arrText = split(strText, ",", 9)<BR>Loop<BR>'close and destroy objects<BR>objFile.Close<BR>Set objFile = Nothing&lt;%<BR>'declare our variables<BR>Dim objFSO , strURL , objFile<BR>'create an instance of the file system object<BR>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")<BR>'this is the csv file downloaded from yahoo<BR>strURL = Server.MapPath("quotes.csv")<BR>'open the file<BR>Set objFile = objFSO.OpenTextFile(strURL)<BR>'while we are not at the end of the file<BR>Do While Not objFile.AtEndOfStream<BR>'store the contents of the file in strText<BR>strText = objFile.readLine<BR>'split the strText <BR>arrText = split(strText, ",", 9)<BR>Loop<BR>'close and destroy objects<BR>objFile.Close<BR>Set objFile = Nothing<BR>Set objFSO = Nothing<BR>%&gt;<BR>&lt;table&gt;<BR>&lt;tr&gt;&lt;td&gt;description&lt;/td&gt;&lt;td&gt;latest figure&lt;/td&gt;&lt;tr&gt;<BR>&lt;tr&gt;&lt;td&gt;symbol&lt;/td&gt;&lt;td&gt;&lt;%= arrText(0) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;last price&lt;/td&gt;&lt;td&gt;&lt;%= arrText(1) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;date&lt;/td&gt;&lt;td&gt;&lt;%= arrText(2) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;time&lt;/td&gt;&lt;td&gt;&lt;%= arrText(3) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;change&lt;/td&gt;&lt;td&gt;&lt;%= arrText(4) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;open&lt;/td&gt;&lt;td&gt;&lt;%= arrText(5) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;high&lt;/td&gt;&lt;td&gt;&lt;%= arrText(6) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;low&lt;/td&gt;&lt;td&gt;&lt;%= arrText(7) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;volume&lt;/td&gt;&lt;td&gt;&lt;%= arrText(8) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;/table&gt; <BR>Set objFSO = Nothing<BR>%&gt;<BR>&lt;table&gt;<BR>&lt;tr&gt;&lt;td&gt;description&lt;/td&gt;&lt;td&gt;latest figure&lt;/td&gt;&lt;tr&gt;<BR>&lt;tr&gt;&lt;td&gt;symbol&lt;/td&gt;&lt;td&gt;&lt;%= arrText(0) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;last price&lt;/td&gt;&lt;td&gt;&lt;%= arrText(1) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;date&lt;/td&gt;&lt;td&gt;&lt;%= arrText(2) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;time&lt;/td&gt;&lt;td&gt;&lt;%= arrText(3) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;change&lt;/td&gt;&lt;td&gt;&lt;%= arrText(4) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;open&lt;/td&gt;&lt;td&gt;&lt;%= arrText(5) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;high&lt;/td&gt;&lt;td&gt;&lt;%= arrText(6) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;low&lt;/td&gt;&lt;td&gt;&lt;%= arrText(7) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;tr&gt;&lt;td&gt;volume&lt;/td&gt;&lt;td&gt;&lt;%= arrText(8) %&gt;&lt;/td&gt;&lt;/tr&gt;<BR>&lt;/table&gt; </P>


<<<----- Return to Asp/VB Script Source Code Questions Page.


Have a Question ? post your questions here. It will be answered as soon as possible.

Check Microsoft .Net Interview Questions for more Microsoft .Net Interview Questions with Answers.

Check .Net Database Interview Questions for more .Net Database Interview Questions with answers

Check Job Interview Questions for more Interview Questions with Answers