I have got 16 buttons and i am generating a random umber from 1 - 16 but then i don't know how to use that number that I've generated to access the variable. I tried "Button" + Order(Ord) but couldn't then access the properties of the variable.
Sub game()
Order(Ord) = ((15 * Rnd()) + 1)
Console.Text = Order(Ord)
test = Order(Ord)
Target = "Button" + test
Ord = Ord + 1
End Sub
If you have a list of the buttons then you can select a list entry at random. Always remember that the first entry in a list or an array has an index of 0.
If you put all the buttons in a Panel, it can be easier to keep them organised: for example, you can get VB.NET to select all the buttons within that panel. Then you can also get it to count them for you, so if you ever change how many buttons there are, you won't need to go through the code changing every applicable instance of 15.
For a random number generator, you'll be better off using the .NET Random class instead of the old VB Rnd() function. You only need one instance of it, so it can be created at the same time as the main form.
Ordermethod does with the value.Please start a new VB.NET Windows Forms project, add a Panel named "TheButtonPanel" to the default form, and as many buttons as you like, just for testing, to the panel.
I have added a simple handler to each of the buttons, so you can see some of the possibilities of getting the code to do work instead of you.
When you run it, it will show the form and automatically click a random button, and the click handler will show you the value of the button's .Text property (because I wanted to put something in the
Game()method). You can still click the buttons to run the click handler.Finally, try to give controls more descriptive names than things like "TheButtonPanel"—I have no idea what would be a good name in your program.