08-07-2013, 08:38 AM
VB6 :
Code:
Public Function RandomString( _
ByVal Length As Long, _
Optional charset As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" _
) As String
Dim chars() As Byte, Value() As Byte, chrUprBnd As Long, i As Long
If Length > 0& Then
Randomize
chars = charset
chrUprBnd = Len(charset) - 1&
Length = (Length * 2&) - 1&
ReDim Value(Length) As Byte
For i = 0& To Length Step 2&
Value(i) = chars(CLng(chrUprBnd * Rnd) * 2&)
Next
End If
RandomString = Value
End Function
Private Sub Command1_Click()
MsgBox RandomString(20)
End Sub



