Tuesday, 17 January 2012

vb.net code for Random number with letter


How to generating random number with letter in vb.net code

Steps to create a random number generator
 Step1:  File new project ->windows forms application -> rename random number with letter generate
Step2:  Drag and drop the one button, four textboxes from tool box
Step3:  Rename button as generate
Step4: Double click the generate button 
Copy and paste this code
Private Sub Button1_Click(ByVal sender AsSystem.Object, ByVale As System.EventArgs) _ Handles Button1.Click
        Dim rand As New Random
        Dim letter As String
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox1.Text = letter & Int(Rnd() * 9)
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox2.Text = letter & Int(Rnd() * 9)
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox3.Text = letter & Int(Rnd() * 9)
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox4.Text = letter & Int(Rnd() * 9)
    End Sub
Step5:  Run the application

You can alternate the code also
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox1.Text = Int(Rnd() * 99) & letter
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox2.Text = "A" & letter & Int(Rnd() * 9)
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox3.Text = letter & "B"& Int(Rnd() * 9)
        letter = ChrW(rand.Next(Asc("A"), Asc("F") + 1))
        TextBox4.Text = letter & Int(Rnd() * 9)
   

No comments:

Post a Comment