I have come here asking for help on how to make my string generator generate the amount of strings typed in TextBox2. For example, if I typed 10 in the box it would generate 10 strings in the RichTextBox1 and if I typed 1 it would generate 1 etc. Here is my code.
Public Function RandomString(ByVal length As Integer) As String
Dim strb As New System.Text.StringBuilder
Dim chars() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
Dim UpperBound As Integer = UBound(chars)
For x As Integer = 1 To length
strb.Append(chars(Int(Rnd() * UpperBound)))
Next
Return strb.ToString
End Function
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Try
System.Diagnostics.Process.Start("Link Removed...")
Catch
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rndstring As String
rndstring = RandomString(24)
RichTextBox1.Text = rndstring
End Sub
What you need to do is modify your click handler for Button1 to repeat the number of times specified in
TextBox2. However, you should verify that the user specified a valid numeric value in the text box as well. Something like this:An extra suggestion might be to change the text box that the user specifies the repeat value to a NumericUpDown control.
Also note that, for large repeat values, the append to the text box
Textproperty would not be efficient due to string immutability so perhaps anotherStringBuilderwould be appropriate.