Support Forums
[How to] Create random strings(upper,lower and integers)[Src] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [How to] Create random strings(upper,lower and integers)[Src] (/showthread.php?tid=18067)

Pages: 1 2


RE: [How to] Create random strings(upper,lower and integers)[Src] - Modestep - 05-12-2011

(05-12-2011, 11:16 AM)euverve Wrote: A slight change version, with number of random strings to generate.

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If StrLength.TextLength <= 0 Then
            MsgBox("Input string length.")
        Else
            StrOutput.Text = RandomString(StrLength.Text)
        End If
    End Sub

    Function RandomString(ByVal val As Integer) As String
        RandomString = ""
        Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
        Const strNumbers As String = "1234567890"
        Dim strTotal As String = strUpper & strLower & strNumbers
        Dim i As Short

        For i = 1 To CInt(val)
            RandomString = RandomString & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
        Next i
    End Function

Screenshot:
[Image: 3iTgN.png]
A good mod, you made the source more clear




RE: [How to] Create random strings(upper,lower and integers)[Src] - モrainee - 05-14-2011

Nice job, I don't know what someone may need this for, but great job. At least it works.