tags:

views:

25

answers:

2

I am getting "Index was outside the bounds of the array." error when using this code:

Dim RandomA As String = "aAÀàÁâÄäÅåĀāĂ㥹ǞǟǺǻÃãÄ"
TextBox1.Text = TextBox1.Text.Replace("a", RandomA((Int(Rnd() * RandomA.Count)) - 1))

I fail to see how the (random) index can be out of bounds?

+2  A: 

Int(Rnd() * RandomA.Count) could return 0, and 0 - 1 is outside the bounds.

John Saunders
A: 

it is an edge condition for sure. the equation evaluates to -1 under certain random number conditions.

Randy