Using the Randomize Statement ASP.NET Style(Method #2)

This code-tip demonstrates show how-to use the new Random Class that isprovided in the .NET framework.  This is a very efficient way of displayingdifferent content every-time.  This code sample is very similar to ClassicASP's random ...

Contributed by
Rating: 3 stars3 stars3 stars3 stars3 stars / 3
July 20, 2001
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement


This code sample is very similar to Classic ASP's randomize method.  Notice we use the NEXT method and provide it a single number that will be used to randomly select something in the Select CASE statement.  This can either be done with

R.NEXT(minvalue, maxvalue) 

Select r.NEXT(1, 8)

or r.NEXT(value)

Select r.NEXT(5)

Here is the code.

<script language="VB" runat="server">
Function MeRandom() as string
Dim r As New Random()
Dim MyContent As String
 Select r.Next(3)
Case 1
MyContent = ("Choice One")
Case 2
MyContent = ("Choice Two")
Case 3
MyContent = ("Choice Three")
Case 4 
MyContent = ("Choice Four")
Case 5
MyContent = ("Choice Five")
Case 6
MyContent = ("Choice Six")
Case Else
MyContent = ("Choice Else")
End Select
Return MyContent
End Function
</script>
<html>
<head>
</head>
<body>
<h1 align="center">Randomize Example .NET Style Demo!</h1>
<form method="post">
<b><% =(MeRandom) %></b><br><br>
<input type="Submit" value="Push to Refresh Page" name="b1">
</form>
</body>
</html>


blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials