Jan 30, 2010 04:00 AM
(This post was last modified: Jan 30, 2010 04:17 AM by DeltaNox.)
I saw this question in another thread so I decided to make a tutorial for it. :)
Don't know if this is the most efficient method but it does the trick.
You need: 1 button (btnGenerate)
and 1 textbox (txtSerial)
Doubleclick the button you just added and add the following code.
1. Empty textbox first when button is pressed:
2. Declarations:
Chars are the characters that will be generated, just add anything in there you want to appear into the fake serial.
3. Loop 1
This will set the lenght of your serial which will be xxxx-xxxx-xxxx-xxxx, if you want it to be something else then simply change the 3 to 4 or wathever you want it to be for example if you put for x = 0 to 5 then you'll be getting a serial like xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
4. -
This will create the "-" except for the first loop.
5. Loop 2
This generates the random symbols and puts them into the textbox, the "for i = 0 to 3" wil create the lenght of each part of the code.
Finally add these two lines:
That's it. If you want to use seperate textboxes instead you can use this code:
(Jan 29, 2010 10:19 AM)fleischi93 Wrote: No one knows how to generate random numbers with capital letters?
I don't want to use the "Case method" I want to generate random numbers with capital letters on every click.
Like
0DK4-5KSE4-KE32-KU6RZ
But NOT the case method. I'd love to know how to do that..
Don't know if this is the most efficient method but it does the trick.
You need: 1 button (btnGenerate)
and 1 textbox (txtSerial)
Doubleclick the button you just added and add the following code.
1. Empty textbox first when button is pressed:
Code
txtSerial.Text = ""2. Declarations:
Code
Dim x As Integer = 0
Dim i As Integer = 0
Dim y As Boolean = False
Dim Chars As Char() = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray()
Dim rand As System.Random = New RandomChars are the characters that will be generated, just add anything in there you want to appear into the fake serial.
3. Loop 1
Code
For x = 0 To 34. -
Code
If y = True Then
txtSerial.Text = txtSerial.Text & "-"
End If5. Loop 2
Code
For i = 0 To 3
Dim intRandom As Integer = rand.Next(Chars.Length)
txtSerial.Text = txtSerial.Text & Chars(intRandom).ToString()
NextFinally add these two lines:
Code
y = True
NextThat's it. If you want to use seperate textboxes instead you can use this code:
Code
TextBox0.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Dim Chars As Char() = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray()
Dim rand As System.Random = New Random
Dim i As Integer = 0
For i = 0 To 3
Dim text0 As Integer = rand.Next(Chars.Length)
Dim text1 As Integer = rand.Next(Chars.Length)
Dim text2 As Integer = rand.Next(Chars.Length)
Dim text3 As Integer = rand.Next(Chars.Length)
TextBox0.Text = TextBox0.Text & Chars(text0).ToString()
TextBox1.Text = TextBox1.Text & Chars(text1).ToString()
TextBox2.Text = TextBox2.Text & Chars(text2).ToString()
TextBox3.Text = TextBox3.Text & Chars(text3).ToString()
Next


![[Image: moonlight_sanctuary.png]](https://moonlight-sanctuary.org/images/moonlight_sanctuary.png)
