3D Array Help....

Posts 1–11 of 11 · Page 1 of 1
3D Array Help....
Could anyone please help me to learn how to save a 3d array in VB.net...... I'm sorta stuck.... even just a save to specific line streamwrite type thing would be great
Why would you need a 3D array at all? If you get that far stuck into an array I'd recommend a struct.

That being said, why not just save each line as a delimited version of each dimension in an array. i.e:

Code:
first dimension <delimiter> second dimension <delimiter> third dimesion
Then just read each line, and parse 3 dimensions from each of those lines?
its a calendar.... and i was proving my IT teacher that i can make a program that implements a 3d array because he said i couldn't, the only problem I'm having is saving it... I can get everything else to work, e.g saving text into the specific day of each month of each year,the problem I'm having is just saving the data to a file for the next time its opened...
make a local database...
and save the year in one table, then in 3 columns, save the month and day and the string or,
make a table called "3darray", then in 4 columns, save the year,month,day and the string..
jason...would those be more efficient than a text file?
Quote Originally Posted by *****179 View Post
make a local database...
and save the year in one table, then in 3 columns, save the month and day and the string or,
make a table called "3darray", then in 4 columns, save the year,month,day and the string..
jason...would those be more efficient than a text file?
Databases are always more efficient than textfiles.

Also, is your data REALLY a 3d array? At the time of my first post I was a little drunk so I didn't pay much attention to it, but now I'm wondering why you could POSSIBLY have a 3D array when dealing with date data.
Quote Originally Posted by Jason View Post


Databases are always more efficient than textfiles.

Also, is your data REALLY a 3d array? At the time of my first post I was a little drunk so I didn't pay much attention to it, but now I'm wondering why you could POSSIBLY have a 3D array when dealing with date data.
The only thing I can think off why he is using a 3d array is only for proving his IT teacher that he can handle 3d arrays...cuz saving date formats in a 3d array would be useless...also structures > arrays(atleast in most cases)
Quote Originally Posted by Blubb1337 View Post
The only thing I can think off why he is using a 3d array is only for proving his IT teacher that he can handle 3d arrays...cuz saving date formats in a 3d array would be useless...also structures > arrays(atleast in most cases)
I'm not saving date formats.... its a calendar with text savable to each day... meaning that for one that covers 5 years there would be a text file with 1860 lines.... plus, i think i got it to do the job i need it to..... its just going to need to have a loop to populate the 1d array with the 3d array's strings.... pretty straight forward, but thanks for your help anyway guys
Quote Originally Posted by utherson601 View Post
I'm not saving date formats.... its a calendar with text savable to each day... meaning that for one that covers 5 years there would be a text file with 1860 lines.... plus, i think i got it to do the job i need it to..... its just going to need to have a loop to populate the 1d array with the 3d array's strings.... pretty straight forward, but thanks for your help anyway guys
You don't have to save the dates w/o text lol.

And if a date is "outdated", you can remove it again.

Do you currently have a 3D-Array for the date or what?

Post some of your current code or so, I don't fully get how you are accessing all the data...I can help you if I have enough information.
Quote Originally Posted by Blubb1337 View Post
You don't have to save the dates w/o text lol.

And if a date is "outdated", you can remove it again.

Do you currently have a 3D-Array for the date or what?

Post some of your current code or so, I don't fully get how you are accessing all the data...I can help you if I have enough information.
well... i actually need the reverse for this code..... i got the bit that wasn't working, working.... now its time for the last bit to reverse it
Code:
Public Function Arrayvaluesave()
        Dim arraysave(2234) As String
        Dim arraysavecheck As Boolean = True
        Dim arraycheck As Boolean = True
        Dim arraysavebol As Boolean = False
        Dim arrsavenumber As Integer = 0
        Dim arrsavemodify As Integer = 0
        Dim write As New StreamWriter("Months.txt")
        Form2.Intyear = 0
        Form2.IntMonth = 0
        Form2.Intday = 0
        Do While arraycheck = True
            If arrsavenumber < 2231 Then
                If Form2.Intday <= 29 Then
                    arraysave(arrsavenumber) = Form2.Arrtext(Form2.Intyear, Form2.IntMonth, Form2.Intday)
                    Form2.Intday += 1
                    arrsavenumber += 1
                Else
                    If Form2.IntMonth <= 10 Then
                        arraysave(arrsavenumber) = Form2.Arrtext(Form2.Intyear, Form2.IntMonth, Form2.Intday)
                        arrsavenumber += 1
                        Form2.IntMonth += 1
                        Form2.Intday = 0
                    Else
                        If Form2.Intyear <= 5 Then
                            arraysave(arrsavenumber) = Form2.Arrtext(Form2.Intyear, Form2.IntMonth, Form2.Intday)
                            arrsavenumber += 1
                            Form2.Intyear += 1
                            Form2.IntMonth = 0
                            Form2.Intday = 0
                        End If
                    End If
                End If
            Else
                arraysavecheck = False
                arraysavebol = True
                arrsavenumber = 1
            End If
            Do While arraysavebol = True
                If arrsavenumber <= 2233 Then
                    write.WriteLine(arraysave(arrsavenumber), arrsavenumber)
                    arrsavenumber += 1
                Else
                    arraysavebol = False
                    arraycheck = False
                End If
            Loop
        Loop
        write.Close()
        MessageBox.Show(arraysave(0))
    End Function
i was thinking more along the lines of
arrsavetext is a 1d array
arrtext is the 3d array
im trying to make them the same just by putting everything in arrtext into a location in arrsavetext then doing a streamwrite for it to save it
Quote Originally Posted by utherson601 View Post
i was thinking more along the lines of
arrsavetext is a 1d array
arrtext is the 3d array
im trying to make them the same just by putting everything in arrtext into a location in arrsavetext then doing a streamwrite for it to save it
Even though I don't recommend using 3D Arrays...(in this case)...

This sure isn't any good method. Database would be way better...and structures would be better aswell...

Ar(5,5,5) already results in 216 textlines.

[highlight="VB.Net"] Private Ar(5, 5, 5) As Integer

Private Sub SaveArray(ByVal SaveLocation As String)
Dim strB As New System.Text.StringBuilder

For x = Ar.GetLowerBound(0) To Ar.GetUpperBound(0)
For y = Ar.GetLowerBound(1) To Ar.GetUpperBound(1)
For z = Ar.GetLowerBound(2) To Ar.GetUpperBound(2)
strB.AppendLine(String.Format("{0},{1},{2};{3}", x, y, z, Ar(x, y, z)))
Next
Next
Next

Using sWrite As New IO.StreamWriter(SaveLocation, False)
sWrite.Write(strB.ToString)
End Using
End Sub

Private Sub RetreiveArray(ByVal FileLocation As String)
If IO.File.Exists(FileLocation) Then
Dim Line As String = ""
Try
Using sRead As New IO.StreamReader(FileLocation)
While Not sRead.EndOfStream
Line = sRead.ReadLine
Dim split() As String = Line.Split(";"c)
Ar(split(0).Split(","c)(0), split(0).Split(","c)(1), split(0).Split(","c)(2)) = split(1)
End While
End Using
Catch ex As *********enceException
End Try
End If
End Sub[/highlight]

Jason probably knows a way faster solution(LINQ or w/e).

My version works aswell though. Might be a bit slow if you have a huge 3D Array...but huge 3D arrays = retarded in this case...

-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------

@Structures

[highlight="VB.Net"]
Private DateList As New List(Of CustomDate)

Public Structure CustomDate
Dim Day As Byte
Dim Month As Byte
Dim Year As Integer
End Structure

Private Sub AddDate(ByVal Day As Byte, ByVal Month As Byte, ByVal Year As Byte)
DateList.Add(New CustomDate With {.Day = Day, .Month = Month, .Year = Year})
End Sub

Private Sub RetreiveDates()
If DateList.Count <> 0 Then
For i = 0 To DateList.Count - 1
With DateList(i)
MsgBox(String.Format("{0}.{1}.{2}", .Day, .Month, .Year))
End With
Next
End If
End Sub

Private Sub SaveDateList(ByVal List As List(Of CustomDate), ByVal FileLocation As String)
Dim strB As New System.Text.StringBuilder

For i = 0 To List.Count - 1
With List(i)
strB.AppendLine(String.Format("{0};{1};{2}", .Day, .Month, .Year))
End With
Next

Using sWrite As New IO.StreamWriter(FileLocation, False)
sWrite.Write(strB.ToString)
End Using
End Sub

Private Function RetreiveDateList(ByVal FileLocation As String) As List(Of CustomDate)
Dim L As New List(Of CustomDate)

Using sRead As New IO.StreamReader(FileLocation)
While Not sRead.EndOfStream
Dim Line As String = sRead.ReadLine
Dim CD As New CustomDate
CD.Day = Line.Split(";"c)(0)
CD.Month = Line.Split(";"c)(1)
CD.Year = Line.Split(";"c)(2)

L.Add(CD)
End While
End Using

Return L
End Function

Private Sub GetData()
DateList = RetreiveDateList("filelocation")
End Sub
[/highlight]

Still have to repeat myself...Databases > Textfiles.
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?