|
 |
aspx thread: need help
Message #1 by "stanley" <schan@m...> on Fri, 25 Aug 2000 23:44:14
|
|
I have tried to run my aspx page. But I get an error, "Compiler Error
Message: BC30451: The name 'Randomize' is not declared.". Could someone
tell me how to fix this problem?
Thanks,
Stan
----------------- code ---------------------------------
<script language="vb" runat="server">
Public Function getRandomCase() As String
Dim intRandom As Integer
Dim strTemp As String
strTemp = ""
Randomize
intRandom = Int((3 - 1 + 1) * Rnd + 1)
Select Case intRandom
Case 1
strTemp = "Case 1"
Case 2
strTemp = "Case 2"
Case 3
strTemp = "Case 3"
Case Else
strTemp = "default"
End Select
getRandomCase = strTemp
End function
</script>
<html>
<head>
<title></title>
</head>
<body>
Random Case = <%= getRandomCase() %>"
</body>
</html>
Message #2 by "Fredrik Normen" <fredrik.normen@s...> on Sun, 27 Aug 2000 11:15:58
|
|
Hi,
It seems like that Randomize dosn't exist in the preview. Maybe it will not
exist at all. But there is a Radnom class in the System namespce.
So I have change your code so here you have a solution how to use Random.
<%@ Import NameSpace="System.Random"%>
<script language="vb" runat="server">
Public Function getRandomCase() As String
Dim intRandom As Long
Dim strTemp As String
strTemp = ""
Dim myRandom As Random = new Random()
intRandom = myRandom.Next(1,4)
Select Case intRandom
Case 1
strTemp = "Case 1"
Case 2
strTemp = "Case 2"
Case 3
strTemp = "Case 3"
Case Else
strTemp = "default"
End Select
return strTemp
End function
</script>
<html>
<head>
<title></title>
</head>
<body>
Random Case = <%= getRandomCase() %>
</body>
</html>
The Random method can be used like this:
Next( int32 minValue, int32 maxValue )
Next( int32 maxValue ) 'This will return a value between 0 to maxValue
Next()
/Fredrik Normen
Message #3 by "Tony Ricci" <tricci@n...> on Sat, 26 Aug 2000 16:22:02 -0700
|
|
Try adding this to the top of your page:
<%@ Import Namespace="Microsoft.VisualBasic.Compatibility.VB6 " %>
-tricci
----- Original Message -----
From: "stanley"
To: "ASP+" <aspx@p...>
Sent: Friday, August 25, 2000 11:44 PM
Subject: [aspx] need help
> I have tried to run my aspx page. But I get an error, "Compiler Error
> Message: BC30451: The name 'Randomize' is not declared.". Could someone
> tell me how to fix this problem?
>
> Thanks,
>
> Stan
>
> ----------------- code ---------------------------------
> <script language="vb" runat="server">
> Public Function getRandomCase() As String
> Dim intRandom As Integer
> Dim strTemp As String
>
> strTemp = ""
> Randomize
> intRandom = Int((3 - 1 + 1) * Rnd + 1)
> Select Case intRandom
> Case 1
> strTemp = "Case 1"
> Case 2
> strTemp = "Case 2"
> Case 3
> strTemp = "Case 3"
> Case Else
> strTemp = "default"
> End Select
> getRandomCase = strTemp
> End function
> </script>
> <html>
> <head>
> <title></title>
> </head>
> <body>
> Random Case = <%= getRandomCase() %>"
> </body>
> </html>
>
> ---
>
>
Message #4 by "Fredrik Normen" <fredrik.normen@s...> on Sun, 27 Aug 2000 11:28:56
|
|
This message is related to my first answer on this question.
You don't need to import the namespace "System.Random" becuase Random is a
class from the System Namespace.
Ths System namespace is imported by default
So here is the code again.
<script language="vb" runat="server">
Public Function getRandomCase() As String
Dim intRandom As Long
Dim strTemp As String
strTemp = ""
Dim myRandom As Random = new Random()
intRandom = myRandom.Next(1,4)
Select Case intRandom
Case 1
strTemp = "Case 1"
Case 2
strTemp = "Case 2"
Case 3
strTemp = "Case 3"
Case Else
strTemp = "default"
End Select
return strTemp
End function
</script>
<html>
<head>
<title></title>
</head>
<body>
Random Case = <%= getRandomCase() %>
</body>
</html>
/Fredrik Normen
Message #5 by "Gregory A. Beamer" <greg.beamer@e...> on Wed, 30 Aug 2000 16:04:59 +0100
|
|
This appears to be something that is not firmed up yet. Without the
randomize statement, it is even worse. I would guess that this is
functionality that is not yet included in .Net.
GB
|
|
 |