|
Random Quote
| Language: |
ASP |
   
Rated by 7 Users
1 Star = Horrible 5 Stars = Perfect
Rate Code Now
|
| Posted By: |
keith |
| Author Website: |
asp or php |
| Posted On: |
6/20/2007 |
| Code Views: |
3177 |
This inserts a random quote into your page. Every time a user reloads, a new one is shown. Either paste this code into your webpage, or call it using SSI (Example in the code sample).
|
<% ' You can either paste this directly into the ASP page ' that you want to show the code in, or put it in ' a separate ASP page and use SSI calls to display it on ' multiple pages... Call it using this: ' <!--#INCLUDE FILE="quote.asp"-->
' Make a file called "Quotes.txt" ' Quotes.txt format: ' quote text1|author1 ' quote text2|author2 ' Example: ' Never miss a good chance to shut up.|Will Rogers
' The next line initializes all the variables Dim MyPath, FConn, File, TmpStr, CNT Dim QuoteArr, QuoteText, QuoteAuthor, LineArr ReDim LineArr(0)
' This line should be your path to the Quotes.txt file MyPath = "/Path/To/Quotes.txt"
' These lines open the text file for reading Set FConn = Server.CreateObject("Scripting.FileSystemObject") Set File = FConn.OpenTextFile(Server.MapPath(MyPath),1)
CNT = 0
' This reads in all the lines of the file Do While Not File.AtEndOfStream TmpStr = File.ReadLine ReDim Preserve LineArr(CNT) LineArr(CNT) = TmpStr CNT = CNT + 1 Loop ' Close the file File.Close Set File = Nothing Set FConn = Nothing
' This finds a random quote from the array Randomize() QuoteArr = Split(LineArr(Int(RND() * Ubound(LineArr))),"|")
QuoteText = QuoteArr(0) QuoteAuthor = QuoteArr(1)
' The output will look like "quote text here - author" Response.Write(QuoteArr(0) & " - " & QuoteArr(1))
%>
View code in Textarea
This code has not been tested by Your WebCode. Use it at your own risk.
Please report any copyright violations.
|
| Reviews |
|
Hide Reviews |
Add Review |
Delete Review
|
Posted by bass_tones on 8/24/2007You can't call it using true SSI, you can only call it from an asp page using the ASP built in file include command similar to the SSI command. | Posted by blake on 6/28/2007Works good, unless you don't have SSI on your sever |
|