By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,696 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,696 IT Pros & Developers. It's quick & easy.

Newb Question on Array Declaration

P: n/a
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.

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
This should help you out.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcn7/html/vaconDeclaringArrays.htm

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemArrayClassCreateInstanceTopic.htm


"HateSpam" <Ha******@nospam.com> wrote in message
news:vg*****************@fe2.columbus.rr.com...
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.

Nov 21 '05 #2

P: n/a
Private mBoard(7, 7) As CBoardPosition

Note that you'll have to instantiate each element of mBoard before you can
use it. You could do something like this:

For Cnt1 As Integer = 0 To 7
For Cnt2 As Integer = 0 to 7
mBoard(Cnt1, Cnt2) = New CBoardPosition
Next Cnt2
Next Cnt1

or just instantiate each one as and when you need it in your code.

hope that helps..
Imran.

"HateSpam" <Ha******@nospam.com> wrote in message
news:vg*****************@fe2.columbus.rr.com...
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.

Nov 21 '05 #3

P: n/a
HateSpam,
In addition to the other comments:

You need to define the array to be 2 dimensional then you need to size the
array to also be 2 dimensional, alternatively you can define & initialize
the array to be 2 dimensional in one statement (as Imran showed)

Define an uninitialized 2 dimensional array
private mBoard as BoardPosition(,)
Initialize a 2 dimensional array mBoard = New BoardPosition (7,7) {} - or -
ReDim mBoard(7,7)

You can also use Preserve to resize an array & preserve the existing
elements in that array

ReDim Preserve mBoard(7,7)

Hope this helps
Jay

"HateSpam" <Ha******@nospam.com> wrote in message
news:vg*****************@fe2.columbus.rr.com...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.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.