You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 [VB.NET] Randomizer {{TUT}} on Tue Feb 08, 2011 12:50 am

Apocalypse

avatar
Master
Loading
What i am simply going to show you today, is how to make a program where you add items in a listbox, you press a button and a random word or name you added will pop up. This is a great tool for raffles.

What you will need:
1 ListBox
1 TextBox
1 Label
3 Buttons


First thing your gonna do is Re-Size the form so its 320x470, once you did that, add the list box, and resize that, but dont take up all the room. then, on the bottom right corner of the list box, just bellow it, place your label. then, place the buttons, and the textbox.

Rename Label1 to "0 Items"
Rename Button1 to "Add"
Rename Button2 to "Randomize"
Rename Button3 to "Clear"

once you have done that, it should look something like this:



thats done now all wee need is the coding.

Double Click Form1, and just bellow Public Class Form1 you are going to enter the following:
Code:
Dim I As Integer = 1
Dim Int As Integer = 1

then, under where it says " Private Sub Form1_Load" type this in:

Code:
Button1.Enabled = False

Now go back to the Design Page, and double click TextBox1. Once in the coding page, type this in:

Code:
  If TextBox1.Text = "" Then
            Button1.Enabled = False
        Else
            Button1.Enabled = True
        End If

Next thing your gonna do, Right above Private Sub TextBox1_TextChanged, you will type:

Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            If TextBox1.Text = "" Then
                Button1.Enabled = False
            Else
                Button1.PerformClick()
            End If
        End If
    End Sub

Back to the Design Page, double click Button1 and type:

Code:
  Dim A As Object
        A = TextBox1.Text
        ListBox1.Items.Add(I.ToString + ". " + A)
        I = I + 1
        TextBox1.Clear()
        TextBox1.Focus()
        If ListBox1.Items.Count = 1 Then
            Label1.Text = "1 Item"
        Else
            Label1.Text = ListBox1.Items.Count.ToString + " Items"
        End If

Now go back and double click Button2, type:

Code:
 If ListBox1.Items.Count = 1 Then
            MsgBox("Error, you need atleast 2 or more items.", MsgBoxStyle.Critical, "Apocalypse Randomizer")
        Else
            Dim Random As New Random
            Random.Next(0, ListBox1.Items.Count)
            Dim A As Object
            A = Random.Next(0, ListBox1.Items.Count.ToString)
            Dim B As Object
            B = ListBox1.Items.Item(A)
            MsgBox("The Winner Is " + B + "! Gratz!", 0, "Randomizer")
        End If

Last thing, double click Button3:
Code:
ListBox1.ClearSelected()

Thats basically it. if you need any help, or have any questions, feel free to PM Me, if this helped at all, or if you liked the tutorial, just + Rep me.

2 Re: [VB.NET] Randomizer {{TUT}} on Tue Feb 08, 2011 1:26 am

Apocalypse

avatar
Master
Loading
Raikou wrote:good to know
quit spamming random crap.

3 Re: [VB.NET] Randomizer {{TUT}} on Tue Feb 08, 2011 2:13 am

Raikou


Spoiler
Loading
Deception wrote:
Raikou wrote:good to know
quit spamming random crap.
it isn't spam i said good to know

4 Re: [VB.NET] Randomizer {{TUT}} on Wed Feb 09, 2011 12:04 am

The Professor

avatar
Contributor
Loading
Nice misc. program Apoc.
I suppose I'll mess around with it when I have the time.



Last edited by Protozoid on Thu Feb 10, 2011 3:37 pm; edited 1 time in total

5 Re: [VB.NET] Randomizer {{TUT}} on Wed Feb 09, 2011 4:38 am

DJ Fresh

avatar
Master
Loading
Protozoid wrote:VB, VB, VB!

Nice misc. program Apoc.
I suppose I'll mess around with it when I have the time.
You always have time nerd. Razz

6 Re: [VB.NET] Randomizer {{TUT}} on Wed Feb 09, 2011 11:28 pm

preset

avatar
Fresh Meat
Loading
The only use for this I can think of that would be relatively useful to most of you is modifying the 'random' number generator on Gaia forums. It's the same idea just reverse.

7 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 4:26 am

iPoison


Fresh Meat
Loading
You know, the max value is one less.
Totally learned that from a class on VB last year.
Even though.. I was A+ against everyone else.
Also, why are you making A an object? A is obviously a String.
And then in button two, A is obviously an Integer, I don't see a reason for you to make it an object.

8 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 4:40 am

Apocalypse

avatar
Master
Loading
iPoison wrote:You know, the max value is one less.
Totally learned that from a class on VB last year.
Even though.. I was A+ against everyone else.
Also, why are you making A an object? A is obviously a String.
And then in button two, A is obviously an Integer, I don't see a reason for you to make it an object.
and is there a problem with any of it?

9 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 4:41 am

iPoison


Fresh Meat
Loading
Deception wrote:
iPoison wrote:You know, the max value is one less.
Totally learned that from a class on VB last year.
Even though.. I was A+ against everyone else.
Also, why are you making A an object? A is obviously a String.
And then in button two, A is obviously an Integer, I don't see a reason for you to make it an object.
and is there a problem with any of it?
I like your reply to that, but still. I'm only stating my opinion.

10 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 4:43 am

Apocalypse

avatar
Master
Loading
iPoison wrote:
Deception wrote:
iPoison wrote:You know, the max value is one less.
Totally learned that from a class on VB last year.
Even though.. I was A+ against everyone else.
Also, why are you making A an object? A is obviously a String.
And then in button two, A is obviously an Integer, I don't see a reason for you to make it an object.
and is there a problem with any of it?
I like your reply to that, but still. I'm only stating my opinion.
Alright then. hey, as long as it works... XD

11 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 3:30 pm

The Professor

avatar
Contributor
Loading
iPoison wrote:You know, the max value is one less.
Totally learned that from a class on VB last year.
Even though.. I was A+ against everyone else.
Also, why are you making A an object? A is obviously a String.
And then in button two, A is obviously an Integer, I don't see a reason for you to make it an object.

Uh, dude. Lmao.

A is an Object in both cases where it was called as a string and an integer if you can't tell, though you are right about the part of it being an integer and a string at the same time too.
Your opinion was useless so no one really cares lmao.

@Preset, then I guess you really haven't gone in depth with programming if that's the only use you can find for a psuedo-number.



Last edited by Protozoid on Thu Feb 10, 2011 11:25 pm; edited 1 time in total

12 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 10:39 pm

DJ Fresh

avatar
Master
Loading
Protozoid wrote:
iPoison wrote:You know, the max value is one less.
Totally learned that from a class on VB last year.
Even though.. I was A+ against everyone else.
Also, why are you making A an object? A is obviously a String.
And then in button two, A is obviously an Integer, I don't see a reason for you to make it an object.

Uh, dude. Lmao.

A is an Object if you can't tell, though you are right about the part of it being an integer too.
Your opinion was useless so no one really cares lmao.

@Preset, then I guess you really haven't gone in depth with programming if that's the only use you can find for a psuedo-number.

Programming doesn't look hard at all.

13 Re: [VB.NET] Randomizer {{TUT}} on Thu Feb 10, 2011 11:12 pm

The Professor

avatar
Contributor
Loading
Death wrote:
Programming doesn't look hard at all.

In your case beeer, looks can be deceiving, looks can be deceiving...

Sponsored content


Loading

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum