Reading TEXT file

K

Kaustubh

Well i have txt file with abt 1000 Sentence i want that each sentence
appear on my website each time diff sentence on each visit on website
! i have done this
<%
set Testfile=Server.CreateObject("Scripting.FileSystemObject")
set TfileStream=Testfile.OpenTextFile("C:\Inetpub\wwwroot\Quates.txt")
TextFormat=TfileStream.ReadLine
%>
<p align="center"><b>
<font face="Arial" size="2" Color="006699">
<i><align="center">
<%=TextFormat%></i></b>
</font>


But it happends for 1 sentense . i have 196 sentence in my txt file .
i want each diff sentence appear on each visit can anyone tell me the
code please ?
 
A

Aaron [SQL Server MVP]

I strongly recommend using a database for this. The following is a kludge
and will be extremely inefficient.

<%
set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso_OpenTextFile(Server.MapPath("/quates.txt"), 1)
f = fs.readall()
fs.close: set fs = nothing: set fso = nothing

lines = split(f, vbCrLf)
randomize
lineToWrite = lines(rnd*(ubound(lines)+0.5))

response.write lineToWrite
%>
 
J

Jeff Cochran

Well i have txt file with abt 1000 Sentence i want that each sentence
appear on my website each time diff sentence on each visit on website
! i have done this
<%
set Testfile=Server.CreateObject("Scripting.FileSystemObject")
set TfileStream=Testfile.OpenTextFile("C:\Inetpub\wwwroot\Quates.txt")
TextFormat=TfileStream.ReadLine
%>
<p align="center"><b>
<font face="Arial" size="2" Color="006699">
<i><align="center">
<%=TextFormat%></i></b>
</font>


But it happends for 1 sentense . i have 196 sentence in my txt file .
i want each diff sentence appear on each visit can anyone tell me the
code please ?

You want what's commonly called a "Fortune Cookie" or "Random Quote"
script. Usually uses a database instead of a text file for
efficiency. Google will find you any number of them, my first quick
search showed:

http://www.bellaonline.com/articles/art16022.asp
http://freescripts.com/script/228.html
http://www.advancescripts.com/detailed/734.html

Or browse the list at aspin.com:

http://www.aspin.com/func/search?tree=aspin&qry=random+quote&cat=pr

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top