473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Newb Question on Array Declaration

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
3 1523
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
1
by: HateSpam | last post by:
Using Visual Studio .NET version of Visual Basic. I am defining a class that has, as a member, an array of another user-defined class. private mBoard as CBoardPosition() The problem comes...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
8
by: User | last post by:
Hi, This is very basic, It may be a repost, if so I'm sorry. The problem is that this declaration : Private strMyArray(100) As String will create an array of string with a length of 101,...
1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
6
by: tommydogs | last post by:
I am just starting out with AxWebBrowser and need help with a simple application. I just want to navigate to a web page, then read in source code. Here's what I have so far: Private Sub...
18
by: mdh | last post by:
>From p112 ( K&R). Given an array declared as static char arr= { { 0,1,........},{0,1,.....}}; let arr be passed as an argument to f. f( int (*arr) ) {....} It is noted that the...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.