• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Read and Write 3D array to a file in VB.net


Broken In
My Problem is i have a 3d integer array which i havenot been able to save successfully as a binary file.

My code is somewhat like this (including a serializable class of which the array is a part)

For i As Integer = 0 To 4
            For j As Integer = 0 To 9
                For k As Integer = 0 To 3
                   array(i, j, k) = 1000 * (j + 1)
                Next k
            Next j
        Next i

        Dim formatter As BinaryFormatter = New BinaryFormatter()
        Dim datafile As FileStream = New FileStream("data.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite)

        Dim x As New class

        formatter.Serialize(datafile, x)

When i read back this file, the array(0, * , *) shows the expected values but the rest i.e array(1, * , *), array(2, *, *) and array(3, *, *) all have values 0. What am i doing wrong. Plz help me out. I used the formatter.deserialize() method.

BTW, if i posted in the wrong spot or the wrong way, plz excuse for me as i am a noob. Thnx in advance.
Top Bottom