ASP Is Fun

Learning ASP
Free Course
Basics
Functions
SQL Commands
Sample Code

Servers / Setup
Host Reviews
Server Setup
Error Tips

Contract ASP
Development

Intro to ASP



 
French Wedding


Fortune Cookie / Random Quote Code - Array



It's always fun to have a fortune cookie on your website, to give a random quote or fortune or message each time the visitor comes by. Note that this version does NOT require a database to work.

First, you need to create the array with the quotes or fortunes or whatever you will be showing. The array is a string array, with each array member being a different quote. So you can use -

Dim Quotes(20)
Quotes(1) = 'The black bird will signify danger.'
Quotes(2) = 'Be sure to eat something red today.'

and so on.

Since you defined the array right in your code, you know how big the array is. Use the randomize function to get a random item in the array. How to use the Randomize Function. If you had 20 items in your array, your randomize function would be:

CurrID = Int((19 * Rnd) + 1)

Now you have an ID number somewhere between 1 and the maximum ID in your database. Now all you have to do is select the matching phrase!

CurrPhrase = Quotes(CurrID)

That's it! Now you can show your item_desc to your user and have different fortunes, quotes, phrases or anything else appear each time they come back!

Fortune Cookie Code Using a Database

ASP Free Game Code


ASP Main Page | ASP Ebooks | Free ASP Course | Contact Lisa
All content copyright © 2008 Minerva WebWorks LLC. All rights reserved.

Irish Wedding


Free Newsletter!

Ebooks
Intro to ASP
ASP SQL DB
Members
Shopping


Introduction to ASP

Romance Tips
Irish Romance
Italian Romance
French Romance

ASP Poll
How do you handle 500 errors?
I don't
Page does nothing
Displays error
Emails error