multidimensional array of classes issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brandenburg
    New Member
    • Mar 2010
    • 3

    multidimensional array of classes issue

    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 multidimensiona l 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
    Code:
         
    Public Class Objectives
    	private zone as Integer
    	private TZone as integer
    
    
            Public Property TargetZone() As Integer
                Get
                    Return TZone
                End Get
                Set(ByVal value As Integer)
                    TZone = value
                End Set
            End Property
    
            Public Property inZone() As Integer
                Get
    		return zone
                End Get
                Set(ByVal value As Integer)
                    Zone = value
                End Set
            End Property
        End Class
    declaration
    Code:
        Private Const MAXTARGETS As Integer = 102
        Private Const GAZETTEER As Integer = 5
        Private Target(MAXTARGETS) As B29.Objectives
        Private B29CurrentZone(MAXTARGETS)() As B29.Objective
    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
    Code:
        
    Private Sub InitialTargetState()
            For i = 0 To MAXTARGETS - 1
                For j = 0 To GAZETTEER - 1
                    Target(i) = New B29.Objectives
                    B29CurrentZone(i)(j) = New B29.Objectives      'initialize zone modifiers
                Next j
            Next i
        End Sub
    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
  • Brandenburg
    New Member
    • Mar 2010
    • 3

    #2
    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:(

    Comment

    • Brandenburg
      New Member
      • Mar 2010
      • 3

      #3
      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
      Code:
          Private B29InZones(MAXTARGETS) As B29.inZone
      
          Public Structure inZone
              Public Zone10 As Integer
              Public Zone11 As Integer
              Public Zone12 As Integer
              Public Zone13 As Integer
              Public Zone14 As Integer
              Public Zone15 As Integer
      
              Public Zone10Loc As Integer
              Public Zone11Loc As Integer
              Public Zone12Loc As Integer
              Public Zone13Loc As Integer
              Public Zone14Loc As Integer
              Public Zone15Loc As Integer
          End Structure
      
              For i = 0 To MAXTARGETS - 1
                  Target(i) = New B29.Objectives
                  B29InZones(i) = New B29.inZone
              Next i
      
              For i = 0 To MAXTARGETS - 1
                  If Obj.TargetName = Target(i).TargetName Then
                      iTargetZone = Target(i).TargetZone
                      iTargetIndex = i
                      Exit For
                  End If
              Next i
      
          Private Function DetermineZoneMods(ByVal zone As Integer, ByVal index As Integer) As Integer
              Select Case zone
                  Case 10
                      iInZone = B29InZones(index).Zone10
                  Case 11
                      iInZone = B29InZones(index).Zone11
                  Case 12
                      iInZone = B29InZones(index).Zone12
                  Case 13
                      iInZone = B29InZones(index).Zone13
                  Case 14
                      iInZone = B29InZones(index).Zone14
                  Case 15
                      iInZone = B29InZones(index).Zone15
              End Select
              Return iInZone
          End Function

      Comment

      Working...