PDA

Click to See Complete Forum and Search --> : Good evening, need some help please(vb.net)


Morphage
Nov 21st, 2002, 04:59 PM
Okay, I am basically bran new at programming, I have never programmed in any other language than vb.net, so yes, I am unexperienced.

I am in the midst of a battleship application, you know, the game.

I am trying to get the application (in Visual Basic.net ) to randomally place points (or ships, which are going to consist of 1 letter) behind certain points. The user will select his or her guesses buy pressing buttons (a series of 100 buttons that form the grid). So I by them pressing the button, they will press the randomly placed object, or button.

So I don't have to just randomly place points on the entire form, but randomize locations in a given section of the form, is that possible? I have read all over msdn library and can't find anything that I can related to what I am trying to do.

If there was a way to select all the buttons, or a universal button term, then I could easily use if-then statements, but I don't think that is going to work.

Thanks for the help in advanced if any is given.

sql_lall
Nov 22nd, 2002, 03:03 AM
I'm not sure whether it's the same in VB.net as in Vb 6.0, but the best way to do this is the 'universal button term' you were talking about.
Just set all the buttons up in an array (the easiest way to do this is either 1) call them all the same thing and click 'yes' when the it asks you whether you wnat to from an array OR 2) make one, Ctrl-C Ctrl-V and click 'yes' when it asks you whether you wnat to from an array.

Either way, when you have the Private Sub Command1_click or whatever, it will come up with an (Index) parameter, which you can use to refer to each button individually.

I'm sorry, you might not understand this, but just look in MSDN about arrays of objects such as buttons.

Machaira
Nov 22nd, 2002, 08:21 AM
VB.NET doesn't support control arrays as VB6 does, but you can do basically the same thing by having a handler for all of the buttons. I don't have .NET at work yet so I can't give you the code but take a look at the Handles keyword.