Have to pick a random number from an arraylist, to generate proper information from a database, its bugging on the rnd line at this moment
Dim rn As New List(Of Integer)
Dim QPass As String
rn.Add(71)
rn.Add(72)
rn.Add(79)
rn.Add(80)
Dim index As Integer = CInt(Math.Floor(Rnd() * 4))
Dim randomValue As Integer = CInt(rn(index))
QPass = randomValue.ToString()
Session("Pt2") = rn
PT2imgImage.ImageUrl = "showImage.ashx?i=" + QPass
PT2imgImage.Width = Unit.Pixel(600)
Here
you are trying to put an Integer (the value selected from the ArrayList), into a variable declared as ArrayList. That won’t work. Use a new variable:
CInt(Math.Floor(...))ensures that the floating point value returned fromRnd() * 4is correctly rounded down and converted into an integer, which can then be used to index an array list. Eventually, you might want to replace this by a more .NET way to get a random number (e.g.Random.Next).Rndis mainly for backwards compatibility.The
CIntaroundrn(index)is required, since you use an old, untypedArrayListinstead of a new, shiny, strongly-typedList(Of Integer). If you use the latter, you can remove the outerCInt.