Friday, January 25, 2013

ID Generator Using Random (Rnd) in Vb6


'To be placed on the command button

Private Sub GenerateID_Click()
Text2.Text = GenerateCode() '<--- Call by Function
End Sub

'Function code that will do the random pick of numbers to be generated.

Public Function GenerateCode()
    strInputString = "123456789012345678901234567890"
 
    intLength = Len(strInputString)
 
    intNameLength = 5
 
    Randomize
 
    strName = ""
 
    For intStep = 1 To intNameLength
        intRnd = Int((intLength * Rnd) + 1)
 
        strName = strName & Mid(strInputString, intRnd, 1)
    Next
 
    GenerateCode = strName
End Function

No comments:

Post a Comment