NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

ASP Magic Eight Ball

Written by Eric Smith, Northstar Computer Systems LLC

If you've got questions about how to do random events, take a look at this sample from CodeAve.com:
dim saying(20)
' set the variable saying with 20 dimensions
saying(1)="As I See It, Yes"
saying(2)="Ask Again Later"
saying(3)="Better Not Tell You Now"
saying(4)="Cannot Predict Now"
saying(5)="Concentrate and Ask Again"
saying(6)="Don't Count On It"
saying(7)="It Is Certain"
saying(8)="It Is Decidedly So"
saying(9)="Most Likely"
saying(10)="My Reply Is No"
saying(11)="My Sources Say No"
saying(12)="Outlook Good"
saying(13)="Outlook Not So Good"
saying(14)="Reply Hazy, Try Again"
saying(15)="Signs Point to Yes"
saying(16)="Very Doubtful"
saying(17)="Without a Doubt"
saying(18)="Yes"
saying(19)="Yes Definitely"
saying(20)="You May Rely On It"
' pick a random number between 1 and 20
randomize
random=int(rnd*20)+1
u_input=request.form("u_input")
' if the user asked a question of the 8 ball display it 
if u_input<> "" then 
response.write saying(random)
else
' if this is the users first visit display this message instead
response.write "Ask a Question to the 8 Ball
and click for your answer" end if
It shows how to create the classic magic eight ball, which randomizes through 20 different sayings. The key to making it work is using the Randomize statement, which causes the Rnd function to work on a completely random sequence of numbers.

Keywords: [ ASP Built-in Functions | Uncategorized ASP Tips ]

Publication Date: 1/10/2001, Last Update: 2/13/2010