Here is what my form looks like:

Open the code view of your form and then create a function called "GenerateRandomString"
Function GenerateRandomString(ByRef length As Integer) As String Randomize() Dim allowableChars As String allowableChars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()" Dim i As Integer For i = 1 To length GenerateRandomString = GenerateRandomString & Mid$(allowableChars, Int(Rnd() * Len(allowableChars) + 1), 1) Next End Function
You can set the allowableChars to anything you want. for instance if you did not want special chars (!@#$% etc...) then you can just remove those from the allowable chars.
Finally on your button click event:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sLgth As String = TextBox2.Text
If TextBox2.Text = "" Then
MsgBox("Please enter a Char. Length")
Else
TextBox1.Text = GenerateRandomString(CInt(sLgth))
End If
End Sub


Sign In
Create Account


Back to top










