我有以下VB代码。我试图让它随机化一个引用,以便在刷新时打印到页面,但它不是为我做的。
有什么明显的错误吗?
<%
Dim quotes As New ArrayList, quoters As New ArrayList
quotes.Add("The Warehouse excites me every single time"): quoters.Add("- Samantha Jones")
quotes.Add("Everyone is just so friendly"): quoters.Add("- Bianca Emit")
quotes.Add("A great place to explore new things!"): quoters.Add("- Adrian Soft")
quotes.Add("I absolutely LOVE The Warehouse!!!!!!!!!!!!!"): quoters.Add("- Adam Jenkins")
quotes.Add("I look forward to it every week!"): quoters.Add("- Mary Binge")
Randomize
Dim quoteNumber As Byte = CInt * (quotes.Count - 1)
Response.Write("""" & quotes(quoteNumber) & """<br />" & vbCrLf)
Response.Write(quoters(quoteNumber))
%>
答案 0 :(得分:0)
Randomize
只是初始化随机数生成器。您需要调用Rnd()
来生成0到1之间的随机数。然后乘以您需要的范围。即count - 1
Dim quoteNumber as Integer = CInt( Rnd() * (quotes.Count - 1) )