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:
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 TextboxPrivate Sub btnAddCap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCap.ClickTextBox1.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.ClickTextBox1.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.ClickTextBox1.AppendText("0123456789")End Sub'Appends the Special Characters in TextboxPrivate Sub btnPunct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPunct.ClickTextBox1.AppendText("!@#$%^&*()_+-=|}{[]\';:,./<>?`~")End SubPrivate Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.ClickDim chars As Char() = TextBox1.Text.ToCharArray()Dim total As Integer = NumericUpDown1.ValueDim cur As Integer = 0Dim endStr As String = ""Dim r As New RandomDo Until cur >= totalDim rr As Integer = r.Next(chars.Count())endStr &= chars(rr)rr = Nothingcur += 1LoopLabel1.Text = endStrEnd SubEnd Class
Final Output:
Create a Random String Generator
Reviewed by code-dev
on
9:57 PM
Rating:
No comments: