|
You ve now created a quotations page that will show a different quotation every time the page is displayed. But you still haven t seen any quotations! It s time to test the page to see how your quotations look in the page.
Run the quotations page
Press F5 to run the page.
Verify that a quotation does appear.
Click the Show Another Quote button in the browser to run the page again. You should see a different quotation. (Because you re working with random numbers, it s statistically possible that you ll see the same quotation, of course.)
Click the button several more times. You should see a selection of quotations.
Depending on how many quotations your quotations.txt file contains, it might not be obvious that you re getting a true random selection. I recommend that you click the button until you re satisfied that you re getting different quotations, including both the first and last quotations in the file.
If your quotations aren t showing up as they should, check the following:
Make sure the RandomQuotes.aspx file and the quotations.txt file are in the same directory.
Make sure you added an extra backslash character (\) in this line:
srQuotes = New System.IO.StreamReader(path & "\ quotations.txt")
Make sure that each quotation is on a single line in the text file (no wrapping) and that there aren t blank lines at the end of the file.
Check that you don t have the file open in your text editor if the StreamReader object can t get exclusive access to a file, the open process fails.
Make sure the quotation and author name are delimited with the correct character.
If you changed the code from splitting the line to simply converting the pipe character to another character, make sure you commented out the line-splitting code.
We ve accomplished what we set out to do read quotations from a text file and display a randomly selected quotation on the page. The RandomQuotes.aspx page works, but it can work more efficiently. In the next section, I ll show you a technique for improving the page.
|