Support Forums
[Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - 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: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] (/showthread.php?tid=17165)



[Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - Resistance - 03-20-2011

Hey guys... Today I am going to show you how to generate random strings. You may call this a Keygen, but an amateur version.

Start off with 2 buttons and a textbox.


Button1 Code [Generate]:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Key As Integer
        Key = Int(Rnd() * 5) 'The number 5 is replaced with the Maximum number of cases you have created.
        Select Key
            Case 0
                TextBox1.Text = "John Ronder"
            Case 1
                TextBox1.Text = "Mary Hudkins"
            Case 2
                TextBox1.Text = "Jessy Gonvolio"
            Case 3
                TextBox1.Text = "Emily Jansen"
            Case 4
                TextBox1.Text = "Josh Federton"
            Case 5
                TextBox1.Text = "Sean Richman"
        End Select
    End Sub

Button2 Code [Copy Text]:
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Clipboard.SetText(TextBox1.Text)
        Catch ex As Exception
            MsgBox("Please Generate a name", 16, "Error")
        End Try
    End Sub

Results Should Look like This:
[Image: dc37fc57670ff4e917d8c77d67b1d01c.png]

Enjoy and don't forget to say thanks if you liked my tutorial.




RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - z3r0c00l - 03-21-2011

Can you put a code that Adds a Case With a Random Name entered by the user?


RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - Resistance - 03-21-2011

(03-21-2011, 06:02 AM)z3r0c00l Wrote: Can you put a code that Adds a Case With a Random Name entered by the user?

Yes definitely, it would be like this:

ButtonX.Click()
TextBox1.Text = My.Settings.*NameOfString*
My.Settings.Save()

To allow custom values with My.Settings and if you would want a in depth tutorial on that stuff, go to my tutorial on My.Settings."WhateverString", CLICK HERE

Then you could make the program have a code like this:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Key As Integer
        Key = Int(Rnd() * 5) 'The number 5 is replaced with the Maximum number of cases you have created.
        Select Key
            Case 0
                TextBox1.Text = My.Settings.*NameOfString0*
            Case 1
                TextBox1.Text = My.Settings.*NameOfString1*
            Case 2
                TextBox1.Text = My.Settings.*NameOfString2*
            Case 3
                TextBox1.Text = My.Settings.*NameOfString3*
            Case 4
                TextBox1.Text = My.Settings.*NameOfString4*
            Case 5
                TextBox1.Text = My.Settings.*NameOfString5*
        End Select
    End Sub

So basically what this code I have written for you is allowing the user to set a value for a string like you said, then it would find the strings value (what the user typed) at random and generate it into TextBox2, because TextBox1 is already being occupied at the moment.


RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - KoBE - 03-30-2011

Should look at storing first and last names in different arrays.. that way you would have even more possibilities with less code.


RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - Pyratepig - 04-02-2011

Cases aren't the best way to do a generator, but then again since you said amateur version, it does fit the post.


RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - Anarchy - 04-02-2011

keep up the amazing work and i will defently be using this Smile


RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - prince of persia - 04-11-2011

I don't think this is generating random number it is just picking one from the list you gave it.


RE: [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] - Resistance - 04-12-2011

(04-11-2011, 02:45 PM)prince of persia Wrote: I don't think this is generating random number it is just picking one from the list you gave it.

Who's generating random numbers? First of all we're using names as results, and they are called Strings. Smart ass.