I am developing a random password generator. Producing numbers by a random search of an Integer array is no problem, however when I try to use strings i.e. letters of the alphabet I hit problems. The number of characters needed for a password is input through selection from a list box. The code below shows the lines which give problems. A Random search of the string array only returns the index and not the element content. Any would most appreciate any help.
Private Sub ButNumandAlpha_Click(sender As Object, e As EventArgs) Handles ButNumandAlpha.Click Dim r As Integer Dim a As New ArrayList Dim num As Integer Dim alpha As Integer a.Add("A") a.Add("B") a.Add("C") a.Add("D") a.Add("E") a.Add("F") a.Add("G") a.Add("H") a.Add("I") a.Add("J") a.Add("K") a.Add("L") a.Add("M") a.Add("N") a.Add("O") a.Add("P") a.Add("Q") a.Add("R") a.Add("S") a.Add("T") a.Add("U") a.Add("V") a.Add("W") a.Add("X") a.Add("Y") a.Add("Z") a.Add("a") a.Add("b") a.Add("c") a.Add("d") a.Add("e") a.Add("f") a.Add("g") a.Add("h") a.Add("i") a.Add("j") a.Add("k") a.Add("l") a.Add("m") a.Add("n") a.Add("o") a.Add("p") a.Add("q") a.Add("r") a.Add("s") a.Add("t") a.Add("u") a.Add("V") a.Add("w") a.Add("x") a.Add("y") a.Add("z") count = ListBox2.SelectedIndex r = (count Mod 2) If r = 0 Then num = count / 2 For x = 0 To num - 1 Dim value As Integer = CInt(Int((9 * Rnd()))) p(x) = value Next alpha = count / 2 For x = num + 1 To count + 1 Dim value As String = CInt(Int((51 * Rnd()))) a(x) = value Next End If password = (p(0) & p(1) & p(2) & p(3) & p(4) & p(5) & p(6) & p(7) & p(8) & p(9) & p(10) & p(11) & p(12) & p(13) & p(14) & p(15) & p(16) & p(17) & p(18) & p(19) & p(20)) RichTextBox1.Text = password End Sub
Last edited by a moderator: