473,382 Members | 1,247 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,382 software developers and data experts.

multidimensional array of classes issue

Brandenburg
I'm writing a game in visual basic 2008 and things are going fairly well with it for the most part.. well until today.. I can declare a 1 dimensional array of a class just fine but cannot for the life of me get the syntax right for a multidimensional array. I usually don't have many issues in writing in VB but this is the first large scale program I have ever written in VB2008 and the 1st large scale uses of classes in VB as well

Here is my code to better illustrate my problem
here is the class..minus most of the properties
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Objectives
  3.     private zone as Integer
  4.     private TZone as integer
  5.  
  6.  
  7.         Public Property TargetZone() As Integer
  8.             Get
  9.                 Return TZone
  10.             End Get
  11.             Set(ByVal value As Integer)
  12.                 TZone = value
  13.             End Set
  14.         End Property
  15.  
  16.         Public Property inZone() As Integer
  17.             Get
  18.         return zone
  19.             End Get
  20.             Set(ByVal value As Integer)
  21.                 Zone = value
  22.             End Set
  23.         End Property
  24.     End Class
declaration
Expand|Select|Wrap|Line Numbers
  1.     Private Const MAXTARGETS As Integer = 102
  2.     Private Const GAZETTEER As Integer = 5
  3.     Private Target(MAXTARGETS) As B29.Objectives
  4.     Private B29CurrentZone(MAXTARGETS)() As B29.Objective
  5.  
I instantiate the code here.. TARGET(i) works perfectly... B29CurrentZone(i)(j) does not.. gives me an error saying it needs a NEW keyword...I think i uderstand why but have no idea how to fix it..already surfed the net and could not find and adequate solution
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub InitialTargetState()
  3.         For i = 0 To MAXTARGETS - 1
  4.             For j = 0 To GAZETTEER - 1
  5.                 Target(i) = New B29.Objectives
  6.                 B29CurrentZone(i)(j) = New B29.Objectives      'initialize zone modifiers
  7.             Next j
  8.         Next i
  9.     End Sub
  10.  
For a work around I could do a 1 dimensional structure but I would prefer not if at all possible.. Just seems to clunky for me
Mar 17 '10 #1
2 1964
just looked target(i)=new b29.objective should be right under the first loop.. just thought i would add that comment before someone corrected me... no edit on this forum it would appear:(
Mar 17 '10 #2
I decided on another way of doing the code.. results are the same, but this way will use an added function I made.. I STILL would really appreciate an answer or explanation how to make a multi-dimensional array of a class or structure object.. thx in advance
Expand|Select|Wrap|Line Numbers
  1.     Private B29InZones(MAXTARGETS) As B29.inZone
  2.  
  3.     Public Structure inZone
  4.         Public Zone10 As Integer
  5.         Public Zone11 As Integer
  6.         Public Zone12 As Integer
  7.         Public Zone13 As Integer
  8.         Public Zone14 As Integer
  9.         Public Zone15 As Integer
  10.  
  11.         Public Zone10Loc As Integer
  12.         Public Zone11Loc As Integer
  13.         Public Zone12Loc As Integer
  14.         Public Zone13Loc As Integer
  15.         Public Zone14Loc As Integer
  16.         Public Zone15Loc As Integer
  17.     End Structure
  18.  
  19.         For i = 0 To MAXTARGETS - 1
  20.             Target(i) = New B29.Objectives
  21.             B29InZones(i) = New B29.inZone
  22.         Next i
  23.  
  24.         For i = 0 To MAXTARGETS - 1
  25.             If Obj.TargetName = Target(i).TargetName Then
  26.                 iTargetZone = Target(i).TargetZone
  27.                 iTargetIndex = i
  28.                 Exit For
  29.             End If
  30.         Next i
  31.  
  32.     Private Function DetermineZoneMods(ByVal zone As Integer, ByVal index As Integer) As Integer
  33.         Select Case zone
  34.             Case 10
  35.                 iInZone = B29InZones(index).Zone10
  36.             Case 11
  37.                 iInZone = B29InZones(index).Zone11
  38.             Case 12
  39.                 iInZone = B29InZones(index).Zone12
  40.             Case 13
  41.                 iInZone = B29InZones(index).Zone13
  42.             Case 14
  43.                 iInZone = B29InZones(index).Zone14
  44.             Case 15
  45.                 iInZone = B29InZones(index).Zone15
  46.         End Select
  47.         Return iInZone
  48.     End Function
  49.  
Mar 18 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jdemello | last post by:
When using a multidimensional associative array to cross-reference data in a second, single-dimensional array, PHP stops processing data after a few iterations. Memory usage according to the task...
2
by: shane | last post by:
Ive searched a fair bit for the answer, but nothing has come up that matches what i want to do. I'm having an issue with passing and assigning pointers to multidimensional arrays. The code: ...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
5
by: whisper | last post by:
Hi: there is an issue that confuses me and the FAQ did not clarify it for me. (Sorry I am just learning!) Let say I define a multidimensional array in my main routine as follows: int...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
12
by: Anil Gupte | last post by:
How can I dimension an array like this: dim info(a as integer, b as string) so I can store somthing like {{"John", 10}{"Dan", 20}{"Jane", 30}} I want to be able to sort this array too, but I...
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.