In this part, you will add a "tip of the day" feature to SEARCH.ASP, which will show a new Visual Basic tip each time a query is run. This feature uses the TextStream object of the File Access component to access a text file of tips and display one at random.
If you don't already have the Magazine project open, open it now. Add the text file TIPS.TXT to your project from the CD-ROM that accompanies this book.
Open TIPS.TXT, and examine the contents. Notice that the file structure has each tip on a separate line. You select a tip at random by reading a random line from the file. In SEARCH.ASP, add the following code below the </TABLE> tag to present the tips:
<H1>Tip of the Day...</H1> <% ` Tip of the day ` Variables Dim objFile Dim objStream Dim TextNumber Dim i Set objFile = Server.CreateObject("Scripting.FileSystemObject") Set objStream = objFile.OpenTextFile(Server.MapPath ("/Magazine") _ + "\tips.txt") Randomize Timer TextNumber = Int(Rnd*30) For i = 0 to TextNumber objStream.SkipLine Next strText = objStream.ReadLine objStream.Close %> <H4><%=strText%></H4>
Your result should look like Figure 8-9 on the following page.
Figure 8-9. Tip of the day.