Multidimentional Arrays

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hey guys, i have the need to use an array for storring information about car repairs

basicly the user starts to enter car details bla bla bla, but when it comes to the damage selection i was thinking of using an array to store the data

dim car1_details(0,2,0,0) as string
will this ^ above give me sumit like this eg

0 0 0 0
repair scratches on , Front bumper, 100, 0)
1
Rear bumper
2
Tail Gate

or will it be like

repair scratches on , front bumper, 100, 0
repair scratches on , rear bumper, 100, 0
repair scratches on , tail gate, 100, 0
 
I slapped together a little console application possibly this could provide some assistance:

VB.NET:
    Sub Main()
        Dim str(0)()()() As String

        '1 X 2
        ReDim str(0)(1)

        '1 X 2 x 3
        ReDim str(0)(0)(2)
        '1x2x3x1
        ReDim str(0)(0)(0)(0)
        ReDim str(0)(0)(1)(0)
        ReDim str(0)(0)(2)(0)

        ReDim str(0)(1)(2)
        '1x2x3x1
        ReDim str(0)(1)(0)(0)
        ReDim str(0)(1)(1)(0)
        ReDim str(0)(1)(2)(0)

        str(0)(0)(0)(0) = "0000"
        str(0)(0)(1)(0) = "0010"
        str(0)(0)(2)(0) = "0020"
        str(0)(1)(0)(0) = "0100"
        str(0)(1)(1)(0) = "0110"
        str(0)(1)(2)(0) = "0120"

        For w As Integer = 0 To 0
            For x As Integer = 0 To 1
                For y As Integer = 0 To 2
                    For z As Integer = 0 To 0
                        Console.WriteLine(str(w)(x)(y)(z))
                    Next
                Next
            Next
        Next
    End Sub

Output:

VB.NET:
0000
0010
0020
0100
0110
0120
 
Since your data is supposed to represent an object, and not just dimensions of unrelated data fields, you should define a class to hold each objects data and use a list or array to hold multiple objects thereof.
 
1. Create an Object :

VB.NET:
<Serializable()> Public Class CarDetails
        private m_yourdetail1 as string
        private m_yourdetail2 as string
        Public Property YourDetail1() As String            
            Get
                Return m_yourdetail1
            End Get

            Set(ByVal value As String)
                m_yourdetail1  = value
            End Set
        End Property

        Public Property YourDetail2() As Integer
            Get
                Return  m_yourdetail2
            End Get

            Set(ByVal value As Integer)
                s m_yourdetail2 = value
            End Set
        End Property

    '--- Add more details here ----

End Class
2. Create an array of the object above.

VB.NET:
Dim objCarDetail(2) as CarDetails
3. Assign Values

VB.NET:
objCarDetail(0) = New CarDetails
objCarDetail(0).YourDetail1="Front Bumper"
objCarDetail(0).YourDetail2=0

objCarDetail(1) = New CarDetails
objCarDetail(1).YourDetail1="Rear Bumper"
objCarDetail(1).YourDetail2=0
 
Back
Top