Create a Random String Generator

This tutorial is all about letters, numbers and special characters jumbled to make a random string generator.

Open your Visual Basic .NET Application.

Step 1:
Create a New Project, go to File Menu and navigate to New > Project then name it RandomStringGenerator (see Image below)



Step 2:

Next, Add a New Form by navigating in Project Menu and Click Add Windows Form. You can change the name of your form if you want (optional).


Step 3:
Add 1 Labe1, 1 NumericUpDown, 1 Button and 1 TextBox (Please refer to the image below).

Label Property
Name: Label1
Text: Label1
Font: Microsoft San Serif, 14.25, Bold

TextBox Property
Name: TextBox1

NumericUpDown Property
Name: NumericUpDown1

1st Button Property
Name: btnGenerate
Text: Generate

2nd Button Property
Name: btnAdd
Text: Add Alphabet

3rd Button Property
Name: btnAddCap
Text: Add Capitalize Alphabet

4th Button Property
Name: btnAddNum
Text: Add Number

5th Button Property
Name: btnPunct
Text: Add Punctuation

Code:



Public Class frmRandomString
 'Appends the Uppercase Alphabet in Textbox
    Private Sub btnAddCap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCap.Click
        TextBox1.AppendText("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    End Sub
 'Appends the Lowercase Alphabet in Textbox


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        TextBox1.AppendText("abcdefghijklmnopqrstuvwxyz")
    End Sub


 'Appends the Number in Textbox
    Private Sub btnAddNum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNum.Click
        TextBox1.AppendText("0123456789")
    End Sub
 'Appends the Special Characters in Textbox
    Private Sub btnPunct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPunct.Click
        TextBox1.AppendText("!@#$%^&*()_+-=|}{[]\';:,./<>?`~")
    End Sub

    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
        Dim chars As Char() = TextBox1.Text.ToCharArray()
        Dim total As Integer = NumericUpDown1.Value
        Dim cur As Integer = 0
        Dim endStr As String = ""
        Dim r As New Random
        Do Until cur >= total
            Dim rr As Integer = r.Next(chars.Count())
            endStr &= chars(rr)
            rr = Nothing
            cur += 1
        Loop
        Label1.Text = endStr
    End Sub
End Class

 
Final Output:



Create a Random String Generator Create a Random String Generator Reviewed by code-dev on 9:57 PM Rating: 5

No comments:

Powered by Blogger.