HomeASP Code Using the Randomize Statement ASP.NET Styl...
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 ...
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>