PEHLA KALMA

PEHLA KALMA
Sanaullah Sajid

random key generator with visual studio

How make random key generator with visual basic or visual studio.
Add one text box and button.


Button 1 code:

TextBox1.Text = GenerateCode()

All code there:

Public Class Form1

    Public Function GenerateCode() As Object
        Dim IntRnd As Object
        Dim IntStep As Object
        Dim strName As Object
        Dim IntNameLength As Object
        Dim IntLength As Object
        Dim StrInputString As Object

        StrInputString = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        IntLength = Len(StrInputString)
        IntNameLength = 15
        Randomize()

        strName = ""

        For IntStep = 1 To IntNameLength
            IntRnd = Int((IntLength * Rnd()) + 1)

            strName = strName & Mid(StrInputString, IntRnd, 1)
        Next
        GenerateCode = strName
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = GenerateCode()
    End Sub
End Class

 
*If you want to change the length of the generated code, just change 'IntNameLength' value.

*If you want to edit the Numbers and letters or Symbols that get randomized then edit the 'StrInputString' value.

*I for one are using it to generate a Activation Key for a user when he buys my product.Just saves time to make up my own code...

*This can be in a variety of different ways.It can help add security etc.