04-17-2011, 08:12 AM
Ill start with saying what this is, the code generates a string with random uppercase,lowercase, and numbers. You can edit how many random characters there will be. Here is the code:
Oke now some explanations
We now have 3 strings, one with uppercase, one with lowercase and one with numbers. Later on we are going to take a random character from the string.
We make a loop to get our random string, you can change the length of the string by changing this number "For i = 1 To CInt("25")" if you change the 25 to 4, then our string only will have 4 characters
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Random())
End Sub
Public Function Random() As String
Random = ""
Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
Const strNumbers As String = "1234567890"
Dim strTotal As String
Dim i As Short
strTotal = strUpper & strLower & strNumbers
For i = 1 To CInt("25")
Random = Random & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
Next i
End Function
End Class
Code:
Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
Const strNumbers As String = "1234567890"
Code:
For i = 1 To CInt("25")
Random = Random & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
Next i