Newb Question on Array Declaration

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am defining a class that has, as a member, an array of another
user-defined class.

private mBoard as CBoardPosition()

The problem comes when I attempt to size the array, it should be an 8x8
grid. When I use:

mBoard = New CBoardPosition (7,7)

When I do this, VB thinks I am trying to send two integers to the New
function of the class, not defining it as a 8x8 2d array. This results
in an error as the new function of CBoardPosition takes no parameters.

What is the proper syntax for this? I know I must be missing something
simple.
 
Hi,

Try this:

Private mBoard(7,7) As CBoardPosition = New CBoardPosition()

Good luck! Ken.
 
Please do not multi-post. Instead, you can cross-post - post to all groups
at the same time.
 
Private mBoard(7,7) As CBoardPosition = New CBoardPosition()
Wouldn't that throw up a compile time error saying something like explicit
initialization not permitted for arrays?
 
Hi,

Yeah, you're right. What was I thinking? Use this instead:

Private mBoard(,) As CBoardPosition

Then to size it:

ReDim mBoard(7,7)

Sorry about that. Ken.

That'll do it. Then
 
Back
Top