Originally Posted by
Roger Fang
I need help with a piece of code that will generate a random mix of numbers and letters which is however long a cd key is. (16 or something letters)
I searched these forums today and couldn't find a related post. Need a visual basic code for this btw hlep is highly appreciated.
Here is the code for my randomizer.
Code:
Private Sub Command1_Click()
Text1 = GenerateCode() 'make sure your textbox is called Text1
End Sub
Public Function GenerateCode()
strInputString = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" ' These are the characters which will be in the code
intLength = Len(strInputString)
intNameLength = Text2 ' This makes it so that what ever number is put in Text2 is how long the code will be
Randomize (Timer) ' Just to make it random
strName = ""
For intStep = 1 To intNameLength
intRnd = Int((intLength * Rnd) + 1)
strName = strName & Mid$(strInputString, intRnd, 1)
Next
GenerateCode = strName
End Function
Hope this helps and that you end up understanding it.